Bug 15638 – no common type for const classes

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-02-02T10:58:00Z
Last change time
2016-02-13T18:50:03Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
schuetzm

Comments

Comment #0 by schuetzm — 2016-02-02T10:58:08Z
import std.stdio; class A { int val; } class B : A { this() { val = 3; } } class C : A { this() { val = 4; } } void main() { const B b; const C c; writeln(true ? b : c); } Error: incompatible types for ((b) : (c)): 'const(B)' and 'const(C)' AFAICS there is no reason why this should be disallowed, considering that the following works: const A a1 = b; const A a2 = c; The common type should be `const(A)`. This seems to be an unintended side-effect of this PR: https://github.com/D-Programming-Language/dmd/pull/125 Discovered by SimonN: http://forum.dlang.org/post/[email protected]
Comment #1 by hsteoh — 2016-02-12T02:00:04Z
Confirmed with git that PR #125 causes this problem.
Comment #2 by hsteoh — 2016-02-12T02:01:20Z
(Or exposed a latent bug in the common type code?)
Comment #3 by hsteoh — 2016-02-12T18:39:04Z
Comment #4 by github-bugzilla — 2016-02-13T18:50:03Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ee586e924e358db194f83f0c16c024d22ceebb99 typeMerge should take modifiers into account when searching for common base class. Fixes issue 15638. Add test case to test suite. https://github.com/D-Programming-Language/dmd/commit/c2c036248a462115f87a7baae352cfd026e66dfc Merge pull request #5450 from quickfur/issue15638 typeMerge should take modifiers into account when searching for common base class