Conditional ?: operator with delegate problem

Hello

I have 2 views, one need to send data back to another, so I use delegates.

in View2 I define delegate variable:

public id @delegate { get; set; }

In View1 I have method defined: MyDelegate
So when I close View2, I pass integer to View1 by @delegate.MyDelegate();

All works correctly, but I have searchbar and 2 tables, and I use ?: operator to make code readable.

private void tableView(UITableView tableView) didSelectRowAtIndexPath(NSIndexPath indexPath)
{
	if (indexPath.row < (isFiltered?searchResults.count:originalTable.count))
	{
		int indxb = indexPath.row;
		NSArray visibleCells = tableView.visibleCells();
		foreach (UITableViewCell cell in visibleCells)
		{
			cell.setAccessoryType(UITableViewCellAccessoryType.None);
		}
		UITableViewCell uncheckCell = tableView.cellForRowAtIndexPath(indexPath);
		uncheckCell.accessoryType = UITableViewCellAccessoryType.Checkmark;
		@delegate.MyDelegate(isFiltered?searchResults[indxb].id:originalTable[indxb].id);
	}
	this.navigationController.popViewControllerAnimated(true);
}

In if (indexPath.row < (isFiltered?searchResults.count:originalTable.count)) is working, but in delegate compiler show 2 errors:

Is bug or I cannot use ?: in my example?

[EDIT}

Forget it, it’s my mistake :slight_smile: But it show that compiler do not warn for problem. Problem is that originalTable is generic NSMutableArray table, so it have my member like id. searchResults is NSArray. So simple trying to get id member from NSArray show this error.

private NSArray searchResults;
...... fill table with any values
int _id = searchResults[indxb].id;

b.r.

This is certainly a bug though, the compiler should never emit that error. You have a more complete testcase I can try?

Trying to reproduce on clean project and it correctly show that array do not contain id. Will try to use most of code from my project to reproduce it (cannot send full project).

b.r.

Okay did something, but project do not show error. Anyway it should not compile, but it this do. Probably with larger project reported error happen. Please check comments in code.

testcase.zip (1.0 MB)

b.r.

Thanks, logged as bugs://72806

I just checked it. You’ve got:

NSLog(searchResults[indxb].id.stringValue);

private NSArray searchResults;

so “id” should be properly callable on that, and it is. What am I missing?

Go to line:

NSLog(searchResults[indxb].id.stringValue); // this should not compile

Put cursor in .id, click F12 and see where it bring us, to public class testItem and it id property. searchResults is defined as private NSArray searchResults; so how compiler knows what object is stored in that array to bring us to testItem class? If this will be NSArray<testItem> then all will be okay. Probably You mean that EVERY object have .id property and that’s why it should compile, right?

As I said, it my project (bigger as this example attached), it cause LPUSH error. In this example it compile without any error. I think, problematic line is:

@delegate.myDelgate(isFiltered?searchResults[indxb].id:testArray[indxb].id);

It contain NSArray and generic NSMutableArray and compiler may be confused (my theory)

I hope I explain it better now? :slight_smile:
b.r.

Ah the way it works with ‘id’ is that it lets you call any known property/method. NSArray (non gen) returns id so it does let you call anything on it. This matches the objc behavior.

That is a bug, and we’ll need a testcase for it.

Okay it’s clear, but if VS point that id to my class which is not related with NSArray, then in my project (bigger) it probably cause LPUSH bug. I Changed it to generic array and it’s okay, but I just report, because it can be hard to spot by somone else or with simple project as I upload.

b.r.