Ticket #377 (closed defect: invalid)
Erroneous incompatible types when casting to enum
Reported by: | Jonno | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | Cobra Compiler | Version: | 0.9.6 |
Keywords: | Cc: |
Description
It's very possible that I'm missing something obvious here, but I am getting an error on what appears to be a safe down-cast from Object? to (a subclass of) Enum?.
The specific method is Enum.parse, which is throwing the following error:
Incompatible types. Cannot assign value of type Object? on the right to TestEnum? on the left.
Full example:
enum TestEnum A, B, C class PossibleEnumCompileIssue def main is shared # This doesn't work/compile: # x as TestEnum? = Enum.parse(TestEnum, 'A') # This works, though: y as TestEnum Enum.tryParse<of TestEnum>('A', out y) # I believe the first line should be equivalent to this? sharp'global::TestEnum z = (global::TestEnum) System.Enum.Parse(typeof(global::TestEnum), "A")'
The compiler rejects the cast even if I check the type of x before casting.
Change History
Note: See
TracTickets for help on using
tickets.