Bug 14093 – [REG2.065] __traits(compiles, cast(Object)(tuple)) is true even if it doesn't compile.

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-31T20:40:00Z
Last change time
2015-06-01T00:06:55Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
kpierre+dlang

Comments

Comment #0 by kpierre+dlang — 2015-01-31T20:40:56Z
This code does not compile on most DMD compiler version on Linux: import std.typecons; void main() { Tuple!(int, "x", int, "y") point; static if (__traits(compiles, {auto newPoint = cast(Object)(point);})) { {auto newPoint = cast(Object)(point);} } } The compiles trait evaluates to true, even though it's impossible to cast a tuple to object. The code compiles if I run it in DPaste version "DMD 2.x Git (cfb5842b49)". It doesn't work in 2.065.0 or commit 7c769ec517e8acc086d92c9dc0d6a680b83f69f0. Since this bug seems to come and go there should probably be a unit test for it.
Comment #1 by sinkuupump — 2015-02-01T05:04:59Z
Introduced in https://github.com/D-Programming-Language/dmd/pull/3009 (In reply to Pierre krafft from comment #0) > The code compiles if I run it in DPaste version "DMD 2.x Git (cfb5842b49)". commit cfb5842b49 seems to be DMD 2.063.x.
Comment #2 by bugzilla — 2015-02-06T04:51:59Z
The error: foo2.d(8): Error: e2ir: cannot cast __tup1850.__expand_field_0 of type int to type object.Object foo2.d(8): Error: e2ir: cannot cast __tup1850.__expand_field_1 of type int to type object.Object is coming from the glue layer. The __traits(compiles, ) does not get that far. The error check needs to be moved up into the front end to fix it.
Comment #3 by k.hara.pg — 2015-02-08T11:47:24Z
Comment #4 by github-bugzilla — 2015-02-11T04:38:41Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1d0268e92e83ec62f0daa548e39c749902e7eb54 fix Issue 14093 - __traits(compiles, cast(Object)(tuple)) is true even if it doesn't compile. Move invalid cast check into Expression::castTo(). https://github.com/D-Programming-Language/dmd/commit/132dcccc5f29732301250ea1a1684b858cf6f555 Merge pull request #4395 from 9rnsr/fix14093 [REG2.065] Issue 14093 - __traits(compiles, cast(Object)(tuple)) is true even if it doesn't compile
Comment #5 by github-bugzilla — 2015-02-21T09:11:22Z
Commits pushed to https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1d0268e92e83ec62f0daa548e39c749902e7eb54 fix Issue 14093 - __traits(compiles, cast(Object)(tuple)) is true even if it doesn't compile. https://github.com/D-Programming-Language/dmd/commit/132dcccc5f29732301250ea1a1684b858cf6f555 Merge pull request #4395 from 9rnsr/fix14093
Comment #6 by wazar.leollone — 2015-05-27T14:20:42Z
This issue is not fully solved. There is simpler example: ----------------------------------------- struct FooBar { int a; int b; } void test14093() { FooBar foo; auto obj = cast(Object)foo; //e2ir: cannot cast foo of type FooBar to type object.Object } ----------------------------------------- Moreover, I think, this issue is solved incorrectly: alias this mechanism should reject `cast(Object)(point._tupleAliasThis_)` variant and continue process the root casting "cast(Object)point" excluding alias this. And result error message should be "Error: cannot cast expression point of type Tuple!(int, "x", int, "y") to object.Object". We are interested in subtyping (alias this, or inheritance) only when it can done its work (casting, .member ...).
Comment #7 by k.hara.pg — 2015-05-30T13:53:03Z
(In reply to Igor Stepanov from comment #6) > This issue is not fully solved. > There is simpler example: > ----------------------------------------- > struct FooBar > { > int a; > int b; > } > > void test14093() > { > FooBar foo; > auto obj = cast(Object)foo; //e2ir: cannot cast foo of type FooBar to > type object.Object > } > ----------------------------------------- Will be fixed by: https://github.com/D-Programming-Language/dmd/pull/4691 > Moreover, I think, this issue is solved incorrectly: alias this mechanism > should reject `cast(Object)(point._tupleAliasThis_)` variant and continue > process the root casting "cast(Object)point" excluding alias this. > And result error message should be > "Error: cannot cast expression point of type Tuple!(int, "x", int, "y") to > object.Object". > We are interested in subtyping (alias this, or inheritance) only when it can > done its work (casting, .member ...). It's rather diagnostic issue. I opened a new minor issue 14632.
Comment #8 by k.hara.pg — 2015-06-01T00:06:55Z