Ticket #258 (closed defect: fixed)

Opened 8 years ago

Last modified 8 years ago

Cobra int (primitive) not recognised as implementing underlying type interfaces

Reported by: hopscc Owned by: Chuck
Priority: major Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:


Discovered this on (cobra) int but suspect it applies to all the cobra
primitive system alias types (int, float, char,...)

The Cobra compiler doesn't recognise that a cobra int implements IComparable interface ( or any of the Interfaces the underlying .Net type supports)

Following contrived example

class IntNotIComp
	def main
		i as int = 47
		i1 as int = 46
		#i as Int32 = 47
		#i1 as Int32 = 46
		b = .chkIGt(i, i1)
		assert b
		print b
	def chkIGt(i as IComparable, i1 as IComparable) as bool
		if i.compareTo(i1) >0
			return true
		return false	


intIcomparable.cobra(7): error: Argument 1 of method "chkIGt" expects type IComparable, but the call is supplying type int.
intIcomparable.cobra(7): error: Argument 2 of method "chkIGt" expects type IComparable, but the call is supplying type int.
Compilation failed - 2 errors, 0 warnings

Whereas if the commented lines are enabled (and the explicit typing to 'int' commented) the cobra compiler allows compilation (modulo a warning to 'Use the builtin type "int32" instead of the struct "Int32"').

Looks like the system alias types need some enhancement either explicitly describing the interfaces they support or copying the interfaces the underlying types support.


typeAlias-chk-implements.patch Download (4.4 KB) - added by hopscc 8 years ago.

Change History

Changed 8 years ago by hopscc

heres a patch (and test) for a partial fix for 'int' that I found is needed for
my treaps implementation.

A better way would be to reflect the interfaces from the underlying implementing class
(hence the commented '_installNativeInterfacesFrom('System'...' placeholder)

Changed 8 years ago by hopscc

Changed 8 years ago by hopscc

  • owner set to Chuck
  • status changed from new to assigned

Changed 8 years ago by Chuck

  • status changed from assigned to closed
  • resolution set to fixed

Thanks for the report and patch. I made use of the test case, but provided a different implementation that installs all the interfaces for primitive types and without hardcoding their names. changeset:2456

Note: See TracTickets for help on using tickets.