Wiki

Ticket #380 (new defect)

Opened 10 years ago

Last modified 10 years ago

CIE caused by local var declaration "x as EnumType".

Reported by: thriwkin Owned by:
Priority: critical Milestone:
Component: Cobra Compiler Version: 0.9.6
Keywords: CIE Cc:

Description

Compiling this with Cobra svn:3116

class Program
    def main is shared
        x as PlatformID
        CobraCore.noOp(x)

causes this CIE:

error: COBRA INTERNAL ERROR / ArgumentOutOfRangeException / 
    Index was out of range. 
    Must be non-negative and less than the size of the collection.; 
    Parameter name: index

The critical code pattern is:

def m
    x as T
    ...

where T references an enum which is defined in another assembly,
for example PlatformID, StringComparison, StringSplitOptions, ... .

Attachments

EnumDecl-sharpInit.patch Download (466 bytes) - added by thriwkin 10 years ago.

Change History

Changed 10 years ago by thriwkin

Changed 10 years ago by thriwkin

  • priority changed from major to critical
  • keywords CIE added
  • version changed from 0.8.0 to 0.9.6

The inner Exception (ArgumentOutOfRangeException) is thrown here:

class EnumDecl is partial
    get sharpInit as String is override
        return .sharpRef + '.' + _declsInOrder[0].name  # <== `_declsInOrder` is empty

When changed to this:

class EnumDecl is partial
    get sharpInit as String is override
        return "0"

the translation to C# is:

x as PlatformID    # PlatformID x = 0;

and all works.

Note
C# 4.0 Spec 6.1.3 Implicit enumeration conversions:
An implicit enumeration conversion permits
the decimal-integer-literal 0 to be converted
to any enum-type and
to any nullable-type whose underlying type is an enum-type.

Note: See TracTickets for help on using tickets.