Bug 13142 – Enums on different classes confuse the compiler

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-16T23:56:00Z
Last change time
2014-08-22T08:04:35Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
mingodad

Comments

Comment #0 by mingodad — 2014-07-16T23:56:52Z
Trying to compile Harmonia with dmd 2.065 I discovered a bug that was not present on previous versions. Sample program to show the bug: ------ class Button { enum TYPE // button type { COMMAND, CHECK, OPTION, } } class Toolbar { enum ButtonTYPE // button type { COMMAND = Button.TYPE.COMMAND, CHECK = Button.TYPE.CHECK, OPTION = Button.TYPE.OPTION, DELIMETER = Button.TYPE.max + 1 } } void main(){} ------ dmd 2.065 : bugEnum.d(4): Error: cannot implicitly convert expression (3) of type int to TYPE LDC - the LLVM D compiler (0.13.0) based on DMD 2.064: The same error. gdc 4.9: The same error. gdc 4.8.1 : Compiles without error.
Comment #1 by k.hara.pg — 2014-07-17T02:02:01Z
(In reply to Domingo Alvarez Duarte from comment #0) > dmd 2.065 : bugEnum.d(4): Error: cannot implicitly convert expression (3) of > type int to TYPE > LDC - the LLVM D compiler (0.13.0) based on DMD 2.064: The same error. > gdc 4.9: The same error. > gdc 4.8.1 : Compiles without error. In 2.064, some incorrect type coercing around enum declaration has been fixed. By that, the error reporting is an expected result from 2.064, and it's not a regression issue. At line 16 in the sample code: DELIMETER = Button.TYPE.max + 1 The type of Button.TYPE.max is Button.TYPE, but the addition result is typed int. In this code, base type of Toolbar.ButtonTYPE is deduced to Button.TYPE, and int is not implicitly convert to it. So the line should be changed to: DELIMETER = cast(Button.TYPE)Button.TYPE.max + 1 or specify the base type of ButtonTYPE as int explicitly: enum ButtonTYPE : int // <-- { COMMAND = Button.TYPE.COMMAND, CHECK = Button.TYPE.CHECK, OPTION = Button.TYPE.OPTION, DELIMETER = Button.TYPE.max + 1 // OK } Although, as I explained, the true bug is in line 16. Therefore the diagnostic message should be fixed to: bugEnum.d(16): Error: cannot implicitly convert expression (3) of type int to TYPE
Comment #2 by k.hara.pg — 2014-07-17T03:18:29Z
Comment #3 by mingodad — 2014-07-17T05:28:29Z
Thanks for the explanation, originally this error message appear when the classes was on different files and the error was reporting to be on the file with "class Button" instead of the file with "class Toolbar". Just in case the error message problem you are trying to fix also cover this: bugEnumButton.d(4): Error: cannot implicitly convert expression (3) of type int to TYPE -----bugEnumButton.d class Button { enum TYPE // button type { COMMAND, CHECK, OPTION, } } ----- -----bugEnumToolbar.d import bugEnumButton; class Toolbar { enum ButtonTYPE // button type { COMMAND = Button.TYPE.COMMAND, CHECK = Button.TYPE.CHECK, OPTION = Button.TYPE.OPTION, DELIMETER = Button.TYPE.max + 1 } } ----- -----bugEnum.d import bugEnumToolbar; void main(){} -----
Comment #4 by github-bugzilla — 2014-07-17T06:30:26Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/accd889abf75935a5d072ce26eefb87992b8d676 fix Issue 13142 - Enums on different classes confuse the compiler https://github.com/D-Programming-Language/dmd/commit/db51609c3c74b71b9cb27c5580371654b15d589b Merge pull request #3779 from 9rnsr/fix13142 Issue 13142 - Enums on different classes confuse the compiler
Comment #5 by k.hara.pg — 2014-07-17T07:07:32Z
(In reply to Domingo Alvarez Duarte from comment #3) > Just in case the error message problem you are trying to fix also cover this: > > bugEnumButton.d(4): Error: cannot implicitly convert expression (3) of type > int to TYPE > [snip] OK, it's properly fixed in git-head. bugEnumToolbar.d(9): Error: cannot implicitly convert expression (3) of type int to TYPE I'll cherry-pick the fix into 2.066 release branch.
Comment #6 by github-bugzilla — 2014-07-17T16:38:22Z
Commit pushed to 2.066 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/5b9f27c9f5038f7d4c25693d015613d8b4164844 Merge pull request #3779 from 9rnsr/fix13142 Issue 13142 - Enums on different classes confuse the compiler
Comment #7 by github-bugzilla — 2014-08-22T08:04:35Z