Chapel: Casting enums with explicit types

Created on 24 Feb 2017  路  2Comments  路  Source: chapel-lang/chapel

Summary of Problem

Casting an enum element with explicit element types to the element type results in a compilation error in some cases.

Steps to Reproduce

Source Code:

The following enum snippet fails to compile:

enum Numbers {one=1:int(64), two};
writeln(Numbers.one: int(64)); // error here

The error is from type.cpp line 260:

// We think that all params should have init values by now.
INT_ASSERT(sym && !sym->symbol()->hasFlag(FLAG_PARAM));

Interestingly, this snippet, which has a slightly altered code path, succeeds in compiling and executing as expected:

type t = int(64);
enum Numbers {one=1:t, two};
writeln(Numbers.one: t); // prints '1'

Associated Future Test(s):

test/types/enum/typed.chpl #6207

Configuration Information

  • Output of chpl --version: chpl Version 1.14.0.8dc84bd
Compiler Bug

Most helpful comment

I'm going to grab this one next, assuming no one has claimed it

All 2 comments

I'm going to grab this one next, assuming no one has claimed it

The internal error is due to failing to recognize that the initial value for the first enum constant is a CallExpr (specifically, a call to a _cast function). Interestingly, removing the explicit size for the int causes the program to work - we only seem to have issues with ints, uints, etc. that involve an explicit size rather than relying on Chapel's default. Still investigating

Was this page helpful?
0 / 5 - 0 ratings