Ticket #262 (assigned defect)

Opened 8 years ago

Last modified 8 years ago

Cobra needs support 'implements' and overloads on properties

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


Currently cobra supports overloads and specifying 'implements'
(for describing that a method provides an implementation of an interface method) on methods but it is not yet provided on properties.

It needs to be because this lack of implementation makes providing a manual 'raw' implementation of an IEnumerator<of T> (for a generic) impossible(*)

since that interface requires properties defining both
.current as <T>
and .current as Object

Heres a minimal impl for a simple generic range enumerator showing the issue.

# very simple Generic Enumerable implementation
class Ranger<of T> implements  IEnumerable<of T> 
	var _start as T
	var _stop as T

	cue init(start as T, endSent as T)
		_start = start
		_stop = endSent
	def getEnumerator as IEnumerator<of T>
		return RangeEnumerator<of T>(_start, _stop)
	def getEnumerator as System.Collections.IEnumerator
		implements System.Collections.IEnumerable
		return .getEnumerator
class RangeEnumerator<of T> implements IEnumerator<of T>
	var _first = false
	var _start as T
	var _stop  as T
	var _currVal as T
	cue init(start as T, stopVal as T)
		_start = start
		_stop = stopVal
		_first = true
	def hasMoreElements as bool
		return _currVal <> _stop
	def nextElement
		_currVal += 1
		# For IEnumerator 
	def dispose
	def reset
		_currVal = _start
		_first = true
	def moveNext as bool
		if not _first
		_first = false	
		if .hasMoreElements
			return true
		return false

	get current as T
		return _currVal
	#get current as Object
	#	return _currVal
	#	# return .current
class Test
	def main is shared
		for i in Ranger<of int>(1,10)
			print i

As is it emits a diagnostic (as expected/desired)

c:\home\hops\src\cobra\Tst\simpleGenericEnum.cobra(18): error: "RangeEnumerator<T>" does not implement interface member "System.Collections.IEnumerator.Current". "RangeEnumerator<T>.Current" is either static, not public, or has the wrong return type. (C#)
warning: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll: (Location of symbol related to previous error) (C#)
c:\home\hops\src\cobra\Tst\simpleEnum.cobra(56): warning: (Location of symbol related to previous error) (C#)
Compilation failed - 1 error, 2 warnings

If the second 'get current as Object' is uncommented it still emits a diagnostic regarding duplicated property names

simpleGenericEnum.cobra(59,6): error: There is already another class member with the name "current".
Compilation failed - 1 error, 0 warnings

A 'raw' implementation provides the interface itself rather than deferring it to a embedded class or using a generator.

This defect only marked as major rather than critical or higher since most Enumerators can be provided as a generator (using yield).
This is not immediately obvious if someone attempts an implementation in the above fashion...


property-overload.patch Download (20.6 KB) - added by hopscc 8 years ago.

Change History

Changed 8 years ago by hopscc

Changed 8 years ago by hopscc

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

patch to

a) refactor and remove duplicated code for various forms for property parsing
b) support property overloads and 'implements' specifications on properties
c) Correct check for (duplicated) method names differing only by case

new and fixed tests.

Note: See TracTickets for help on using tickets.