Wiki

Ticket #256 (new defect)

Opened 7 years ago

Last modified 7 years ago

This code not implementing all interfaces' methods compiles a broken assembly.

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

Description

This code is incorrect because it doesn't implement IEnumerable<of T>.getEnumerator but it compiles.

use System.Collections
use System.Collections.Generic

namespace Test

	class ReadOnlyList<of T> implements IEnumerable, IEnumerable<of T>

		var _list as IList<of T>

		cue init(list as IList<of T>)
			test
				ints = ReadOnlyList<of int>(List<of int>(@[1, 2, 3, 4]))
				assert ints.count == 4
				assert ints.contains(1)
				assert ints.indexOf(3) == 2
				assert ints[2] == 3
				assert ints.isReadOnly
				total = 0
				for i in ints
					total += i
				assert total == 10
			body
				base.init
				_list = list

		get count as int
			return _list.count

		def contains(item as T) as bool
			return _list.contains(item)

		def indexOf(item as T) as int
			return _list.indexOf(item)

		get [index as int] as T
			return _list[index]

		get isReadOnly as bool
			return true

		def getEnumerator as IEnumerator?
			return _list.getEnumerator

Change History

Changed 7 years ago by nevdelap

  • summary changed from Code not implementing all interfaces' methods compiles a broken assembly. to This code not implementing all interfaces' methods compiles a broken assembly.

Changed 7 years ago by Chuck

That's strange that the C# back-end does not complain (or Cobra eats the error).

Changed 7 years ago by Chuck

At least on Mono on Mac, the error is reported if I explicitly specify the native compiler like so:

$ cobra -native-compiler:/usr/bin/gmcs x-implement-enumerable.cobra
x-implement-enumerable.cobra(3): error: "A<T>" does not implement interface member
"System.Collections.Generic.IEnumerable<T>.GetEnumerator()" and the best implementing
candidate "A<T>.GetEnumerator()" return type "System.Collections.IEnumerator"
does not match interface member return type
"System.Collections.Generic.IEnumerator<T>" (C#)

But the error is not reported with this:

$ cobra x-implement-enumerable.cobra

In which case Cobra.Sharp.dll is used. Either that version of the Mono C# compiler is not reporting the error, or Cobra is not reading errors properly when using the DLL.

Changed 7 years ago by hopscc

Error specific to mono - emits diagnostic as expected on windows (XP)

c:\home\hops\src\cobra\Tst\enumErr.cobra(6): error: "Test.ReadOnlyList<T>" does
not implement interface member "System.Collections.Generic.IEnumerable<T>.GetEnumerator()". "Test.ReadOnlyList<T>.GetEnumerator()" 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\enumErr.cobra(41): warning: (Location of symbol related to previous error) (C#)
Compilation failed - 1 error, 2 warnings
Note: See TracTickets for help on using tickets.