Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2232,8 +2232,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
if (!em.ed.isAnonymous())
em.ed.memtype = t;
}
Expression e = new IntegerExp(em.loc, 0, Type.tint32);
e = e.implicitCastTo(sc, t);
Expression e = new IntegerExp(em.loc, 0, t);
Copy link
Contributor

@marler8997 marler8997 Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too familiar with the AST, but @LemonBoy's change "looks" more correct:

Expression e = t.defaultInitLiteral(em.loc);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first option also, but for some reason it led to segfaults when running the tests. From my point of view, enums are an enumeration of constants that are represented by integers behind the scenes, so this solution looks correct (notice that the cast is not needed anymore)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trouble is there is significant code depending on it being 0. A deprecation cycle will be needed. @LemonBoy 's solution is more correct, but your test case is better. Both of you fixing the same bug is a pity, as now I have to close one. :-(

Copy link
Contributor

@marler8997 marler8997 Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah merging this one first seems reasonable.

@RazvanN7 The language spec doesn't say anything about enums being "integers behind the scenes" (https://dlang.org/spec/enum.html). In fact, if enums had this restriction you couldn't do things like this:

enum message = "MyMessage"; // not an integer behind the scenes

e = e.ctfeInterpret();

// save origValue for better json output
Expand Down
5 changes: 5 additions & 0 deletions test/compilable/test18578.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum Foo { foo1 }
enum Bar : Foo { bar }

void main()
{}
4 changes: 2 additions & 2 deletions test/fail_compilation/diag7477.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag7477.d(13): Error: cannot implicitly convert expression `0` of type `int` to `Foo`
fail_compilation/diag7477.d(20): Error: cannot implicitly convert expression `0` of type `int` to `string`
fail_compilation/diag7477.d(13): Error: integral constant must be scalar type, not `Foo`
fail_compilation/diag7477.d(20): Error: integral constant must be scalar type, not `string`
---
*/

Expand Down