Ticket #142 (assigned defect)

Opened 10 years ago

Last modified 7 years ago

problem when using an object variable of nilable generic type

Reported by: jonathandavid Owned by:
Priority: minor Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: generics, nilable Cc:


The following program triggers a runtime assertion, complaining that myT is nil. It is as if the compiler did not realize that T is taking the value int?, and that therefore "myT" should be allowed to be nil.

class G<of T>
    var myT as T

class Program
    var g = G<of int?>()

    def main is shared
        p = Program()


ticket142.patch Download (1.1 KB) - added by eric.sellon 10 years ago.

Change History

Changed 10 years ago by eric.sellon

  • owner set to eric.sellon
  • status changed from new to assigned

Changed 10 years ago by eric.sellon

Changed 10 years ago by eric.sellon

Let me know if there's any problems with this patch. Thanks.

Changed 10 years ago by Chuck

  • owner eric.sellon deleted

The patch creates a new bug that is obviously related. Consider this program:

class A<of T>

	var myT as T

	cue init
		trace .myT
class Program

	def main
#		a = A<of int?>()
		b = A<of String>()

It should throw an exception because .myT will be nil at the end of .init, but it does not when the patch is applied.

This issue between generics and nilable is tricky because Cobra treats nilable uniformly across types while the .NET run-time does not.

Changed 9 years ago by Chuck


Changed 7 years ago by Charles

bump again

Note: See TracTickets for help on using tickets.