Open cassella opened 6 years ago
Thanks for reporting @cassella!
This seems like a natural follow-up to #5414. @lydia-duncan might have more info.
For more information, I tried compiling the internal error cases with --devel
to get the actual error messages:
enumScopeTest(2);
enumScopeTest(3);
proc enumScopeTest(param x) {
enum Numbers {one=x:int, two, three};
writeln(Numbers.one);
}
> chpl a.chpl --devel
a.chpl:3: In function 'enumScopeTest':
a.chpl:5: error: use of 'one' before encountering its definition, type unknown
enumScopeTest();
param x = 2;
proc enumScopeTest() {
enum Numbers {one=x, two, three};
writeln(Numbers.one);
}
> chpl b.chpl --devel
$CHPL_HOME/modules/standard/Types.chpl:607: internal error: assertion error [type.cpp:353]
Note: This source location is a guess.
Based on looking at the code last week, I suspect something is preventing param folding to occur when it resolves the init expression. I'm disappointed, but not surprised, since it goes through a specialized code path that was broken in a pretty stupid way before I fixed it slightly
I'm not sure whether we should limit enum constant values to compile time constants, but agree that if we do, we should document that limitation. I'll bring that up at our weekly status meeting with the rest of my enum notes.
Please open a PR to check these into the testing system :)
@mppf - was this case handled by your open branch?
@lydia-duncan - thanks for asking. My PR changes some of the ways in which enum constants are initialized but I don't think it fundamentally changes this bug. I think what's going on here is that the enum's constant isn't being substituted appropriately during function resolution. Perhaps the change you proposed (changing where enum functions are stored in the AST) might help. Alternatively, it might be as simple as passing along (and using) a SymbolMap in to ensureEnumTypeResolved.
PR #10114 will retire
test/types/enum/scope-param-offset-type-2.chpl
This issue seems loosely related to #10115 in that it's the compiler working hard to compute the param values of the enums that's going off the rails. I could imagine retiring these futures either by making our computation of enums' param values more robust, or by having the compiler stop trying so hard to compute their values at compile-time.
@vasslitvinov I think github was overzealous in closing this issue due to the last paragraph in 4881bf6. test/types/enum/scope-param-offset-concrete.chpl is still a failing future.
I was reminded of this by #22307 .
github also isn't showing me a Reopen button.
Summary of Problem
A few uses of a scoped enum with an offset fail to compile, when I think they should work.
Steps to Reproduce
Source Code:
[ edit 7/19/2024 cassella -- only the last of these examples still fails. ]
Maybe it needs to be reassured that
x
is an int param?Try to impart this reassurance a different way?
It also doesn't work if the
param x
is global (and the function the enum is within is now concrete):It works if the
enum
andwriteln
are at file scope withx
.Edit 3/15/2019: The error for this is now:
Edit, part 2: I also noticed that if the call to
enumScopeTest()
is moved to after the function's definition, or even to just after theparam x = 2
line, it compiles and runs.FWIW, the spec doesn't spell out in
7.2 Enumerated Types
that theinit-part
expression has to be a param.Associated Future Test(s):
test/types/enum/scope-param-offset-type.chpl
test/types/enum/scope-param-offset-type-2.chpl
test/types/enum/scope-param-offset-concrete.chpl
test/types/enum/scope-param-offset.chpl
[edit 11/1 cassella: add links to futures ]
Configuration Information
This is with
chpl
built from master late Friday,