Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 6 commits into from

2 participants

David Hara Kenji
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) &&
Hara Kenji Collaborator
9rnsr added a note

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

David
Dav1dde added a note

didn't think of that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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)));
Hara Kenji Collaborator
9rnsr added a note

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

David
Dav1dde added a note

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
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"; } }
Hara Kenji Collaborator
9rnsr added a note

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
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) &&
Hara Kenji Collaborator
9rnsr added a note

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
Hara Kenji
Collaborator

Did you run phobos unit test in your local?

Hara Kenji
Collaborator

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

Hara Kenji
Collaborator

Ping?

David

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

Hara Kenji
Collaborator

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

David

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

Hara Kenji
Collaborator

OK. Changelog conflict is resolved.

Hara Kenji 9rnsr merged commit 803aa7c into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 19, 2012
  1. David

    fixed toImpl conflict

    Dav1dde authored
  2. David

    added tests for bug 7660

    Dav1dde authored
  3. David
  4. David

    reworked fix

    Dav1dde authored
  5. David

    changed toImpl fix as proposed

    Dav1dde authored
  6. David

    removed changelog notes

    Dav1dde authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 1 deletion.
  1. +7 −1 std/conv.d
8 std/conv.d
View
@@ -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 == class) &&
isSomeString!T)
{
return toStr!T(s);
@@ -959,6 +959,12 @@ unittest
assert(to!string(a) == "null");
a = new A;
assert(to!string(a) == "an A");
+
+ // Bug 7660
+ class C { override string toString() { return "C"; } }
+ struct S { C c; alias c this; }
+ S s; s.c = new C();
+ assert(to!string(s) == "C");
}
/// ditto
Something went wrong with that request. Please try again.