Thread overview
opCast problem with 2.060
Jul 25, 2012
Namespace
Jul 25, 2012
Jonathan M Davis
Jul 25, 2012
Namespace
July 25, 2012
[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. What is the problem now?
July 25, 2012
On Wednesday, July 25, 2012 14:59:15 Namespace wrote:
> With 2.059 both works fine. What is the problem now?

If you find a bug with the latest on github or with the beta (which was just released: http://forum.dlang.org/post/500E674B.1050709@digitalmars.com ), please report them. And if something worked with 2.059, please mark it as a regression. If the new behavior is actually correct, then the bug will be closed appropriately, but we'd like to catch all of the regressions that we can before 2.060 gets released. Ideally, there wouldn't be _any_ new regressions released with 2.060.

- Jonathan M Davis
July 25, 2012
> If you find a bug with the latest on github or with the beta (which was just
> released: http://forum.dlang.org/post/500E674B.1050709@digitalmars.com ),
> please report them. And if something worked with 2.059, please mark it as a
> regression.

Next time. ;) I'm still searching.