Bug 8434 – [Regression 2.058] cannot implicitly convert expression (vs1.opCast()) of type const(Vector2D) to object.Object

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-25T07:29:00Z
Last change time
2012-07-28T23:14:22Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
rswhite4

Comments

Comment #0 by rswhite4 — 2012-07-25T07:29:16Z
[code] import std.conv : to; class Vector2D(T) { public: T x, y; this(T x, T y) { this.x = x; this.y = y; } U opCast(U)() const { return new U(x, y); } } alias Vector2D!(short) Vector2s; alias Vector2D!(float) Vector2f; void main() { Vector2s vs1 = new Vector2s(42, 23); Vector2s vs2 = new Vector2s(42, 23); assert(vs1 == vs2); } [/code] prints: dmd -w -O -property -unittest -debug -of"vec_test_2060" "vec_test_2060.d" (im Verzeichnis: D:\D\D_Scripts\Test 4) vec_test_2060.d(13): Error: no constructor for Object vec_test_2060.d(24): Error: template instance vec_test_2060.Vector2D!(short).Vector2D.opCast!(Object) error instantiating Kompilierung fehlgeschlagen. And this code: [code] import std.conv : to; class Vector2D(T) { public: T x, y; this(T x, T y) { this.x = x; this.y = y; } U opCast(U : inout(Vector2D!V), V)() const { return new U(x, y); } } alias Vector2D!(short) Vector2s; alias Vector2D!(float) Vector2f; void main() { Vector2s vs1 = new Vector2s(42, 23); Vector2s vs2 = new Vector2s(42, 23); assert(vs1 == vs2); } [/code] prints: dmd -w -O -property -unittest -debug -of"vec_test_2060" "vec_test_2060.d" (im Verzeichnis: D:\D\D_Scripts\Test 4) vec_test_2060.d(24): Error: template instance opCast!(Object) opCast!(Object) does not match template declaration opCast(U : inout(Vector2D!(V)),V) vec_test_2060.d(24): Error: function expected before (), not vs1.opCast!(Object) of type void vec_test_2060.d(24): Error: template instance opCast!(Object) opCast!(Object) does not match template declaration opCast(U : inout(Vector2D!(V)),V) vec_test_2060.d(24): Error: function expected before (), not vs2.opCast!(Object) of type void Kompilierung fehlgeschlagen. If i add to the last code this: [code] const(U) opCast(U = typeof(this))() const { return this; } [/code] I get: dmd -w -O -property -unittest -debug -of"vec_test_2060" "vec_test_2060.d" (im Verzeichnis: D:\D\D_Scripts\Test 4) vec_test_2060.d(28): Error: cannot implicitly convert expression (vs1.opCast()) of type const(Object) to object.Object vec_test_2060.d(28): Error: cannot implicitly convert expression (vs2.opCast()) of type const(Object) to object.Object Kompilierung fehlgeschlagen. With 2.059 both works fine.
Comment #1 by k.hara.pg — 2012-07-28T03:54:44Z
Sorry, are these code really works in 2.059? As far as I know, there is a problem around equality comparison of class objects which have user-defined opCast. But the beginning of it (2011/08/09) is older than 2.059 (2012/04/12 released). And, I've tried to reproduce the problem, but in 2.059, same errors have occurred.
Comment #2 by mike — 2012-07-28T04:39:44Z
It's trying to call opCast!(Object) when comparing two objects. This "regression" was introduced with 2.058. But not everyone agrees it a regression: http://lists.puremagic.com/pipermail/dmd-beta/2012-February/001274.html and http://lists.puremagic.com/pipermail/dmd-beta/2012-February/001276.html
Comment #3 by k.hara.pg — 2012-07-28T08:56:25Z
(In reply to comment #2) > It's trying to call opCast!(Object) when comparing two objects. > This "regression" was introduced with 2.058. > > But not everyone agrees it a regression: > http://lists.puremagic.com/pipermail/dmd-beta/2012-February/001274.html > and > http://lists.puremagic.com/pipermail/dmd-beta/2012-February/001276.html Wow, it had been reported in dmd-internal ML with 2.058 beta? I didn't noticed it. OK. I agree this is an actual regression, and it should be fixed as far as possible. https://github.com/D-Programming-Language/dmd/pull/1068
Comment #4 by github-bugzilla — 2012-07-28T14:37:19Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/752f94c833bee38444340cff8186c9971388964f fix Issue 8434 - cannot implicitly convert expression (vs1.opCast()) of type const(Vector2D) to object.Object This is a regression of 2.058, by fixing issue 4088. The equality comparison of class objects should not run opCast. https://github.com/D-Programming-Language/dmd/commit/f3d5843fcb52600ddc0edcc2b04aa86ce48bfab1 Merge pull request #1068 from 9rnsr/fix8434 Issue 8434 - cannot implicitly convert expression (vs1.opCast()) of type const(Vector2D) to object.Object
Comment #5 by github-bugzilla — 2012-07-28T22:23:33Z