Bug 7660, incorrect toImpl overload for struct with alias this to class #482

Merged
merged 6 commits into from Apr 21, 2012

2 participants

@9rnsr 9rnsr and 1 other commented on an outdated diff Mar 12, 2012
std/conv.d
@@ -930,7 +930,7 @@ T toImpl(T, S)(S s, in T leftBracket, in T keyval = ":", in T separator = ", ",
/// ditto
T toImpl(T, S)(S s)
- if (is(S : Object) &&
+ if (is(S : Object) && !is(S == struct) &&
@9rnsr
D Programming Language member
9rnsr added a line comment Mar 12, 2012

I think is(S == class) is better than is(S : Object) && !is(S == struct).

@Dav1dde
Dav1dde added a line comment Mar 12, 2012

didn't think of that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@9rnsr 9rnsr and 1 other commented on an outdated diff Mar 12, 2012
std/conv.d
@@ -959,6 +959,13 @@ unittest
assert(to!string(a) == "null");
a = new A;
assert(to!string(a) == "an A");
+
+ // Bug 7660
+ class C { string toString() { return "C"; } }
+ struct S { C c; alias c this; }
+ S s; s.c = new C();
+ static assert(__traits(compiles, to!string(s)));
@9rnsr
D Programming Language member
9rnsr added a line comment Mar 12, 2012

This static assert is redundant, because the next run-time assertion implicitly needs that itself is compilable.

@Dav1dde
Dav1dde added a line comment Mar 12, 2012

I added it to stress, that this bug is fixed and if it occurs again you know it's a regression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@9rnsr 9rnsr commented on an outdated diff Mar 12, 2012
std/conv.d
@@ -959,6 +959,13 @@ unittest
assert(to!string(a) == "null");
a = new A;
assert(to!string(a) == "an A");
+
+ // Bug 7660
+ class C { string toString() { return "C"; } }
@9rnsr
D Programming Language member
9rnsr added a line comment Mar 12, 2012

You need adding override keyword for toString.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@9rnsr 9rnsr commented on an outdated diff Mar 13, 2012
std/conv.d
@@ -930,7 +930,7 @@ T toImpl(T, S)(S s, in T leftBracket, in T keyval = ":", in T separator = ", ",
/// ditto
T toImpl(T, S)(S s)
- if (is(S : Object) &&
+ if (is(S == Object) &&
@9rnsr
D Programming Language member
9rnsr added a line comment Mar 13, 2012

No, == Object and == class are obviously different.
The former returns true only if S equals to Object, and the latter can tests whether S is a kind of class type (not only Object, and user-defined class types).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@9rnsr
D Programming Language member

Did you run phobos unit test in your local?

@9rnsr
D Programming Language member

Github doesn't send notify e-mail when you push only commits.
If you add some changes, please add some comment together.

@9rnsr
D Programming Language member

Ping?

@Dav1dde

(S : Object) → (S == class)

@9rnsr
D Programming Language member

Now, you can check your pull's result in Pull Tester.
It shows to you the needing of rebasing.

@Dav1dde

Should work now?
I removed the changelog note, since there's no real place for it (no 2.060 section)

@9rnsr
D Programming Language member

OK. Changelog conflict is resolved.

@9rnsr 9rnsr merged commit 803aa7c into dlang:master Apr 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment