Wiki

Ticket #232 (new defect)

Opened 7 years ago

Last modified 7 years ago

Small inconsistency in 'if a inherits B' semantics.

Reported by: nevdelap Owned by:
Priority: minor Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

Once the 'a inherits B' is found to be true and a is allowed to be used as a B it would be nice if it was allowed in subsequent parts of the same expression rather than needing to wait until the next statement.

The second and third if statements here are the example.

In other words 'if x, if y, do something' should be equivalent to 'if x and y, do something'.

I hope I'm being clear enough.

class A
	pass

class B inherits A
	pass

class P
	var _list as List<of B> is shared

	def main is shared
		a as A = B()
		#_list.add(a) No allowed, ok.
		if a inherits B
			_list.add(a) # Magically allowed by Cobra.
		if a inherits B
			if not _list.contains(a) # Ditto.
				_list.add(a)
		if a inherits B and not _list.contains(a) # error
			_list.add(a)

error: Argument 1 of method "contains" expects type B?, but the call is supplying type A.

Change History

Changed 7 years ago by Chuck

You are being clear and I totally agree and have wanted this for awhile. I just haven't gotten to it. The same thing applies to non-nil:

foo as Foo?
# ...
if foo and obj.bar(foo)  # this should work even if obj's .bar method requires a non-nil Foo

These are related in terms of implementation.

Changed 7 years ago by Chuck

  • summary changed from Small inconsistency in 'a inherits B' semantics. to Small inconsistency in 'if a inherits B' semantics.
Note: See TracTickets for help on using tickets.