Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Merged
merged 6 commits into from about 2 years ago

2 participants

David Herberth Hara Kenji
std/conv.d
... ...
@@ -930,7 +930,7 @@ T toImpl(T, S)(S s, in T leftBracket, in T keyval = ":", in T separator = ", ",
930 930
 
931 931
 /// ditto
932 932
 T toImpl(T, S)(S s)
933  
-    if (is(S : Object) &&
  933
+    if (is(S : Object) && !is(S == struct) &&
2
Hara Kenji Collaborator
9rnsr added a note March 12, 2012

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

David Herberth
Dav1dde added a note March 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
std/conv.d
... ...
@@ -959,6 +959,13 @@ unittest
959 959
     assert(to!string(a) == "null");
960 960
     a = new A;
961 961
     assert(to!string(a) == "an A");
  962
+
  963
+    // Bug 7660
  964
+    class C { string toString() { return "C"; } }
  965
+    struct S { C c; alias c this; }
  966
+    S s; s.c = new C();
  967
+    static assert(__traits(compiles, to!string(s)));
2
Hara Kenji Collaborator
9rnsr added a note March 12, 2012

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

David Herberth
Dav1dde added a note March 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
std/conv.d
... ...
@@ -959,6 +959,13 @@ unittest
959 959
     assert(to!string(a) == "null");
960 960
     a = new A;
961 961
     assert(to!string(a) == "an A");
  962
+
  963
+    // Bug 7660
  964
+    class C { string toString() { return "C"; } }
1
Hara Kenji Collaborator
9rnsr added a note March 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
std/conv.d
... ...
@@ -930,7 +930,7 @@ T toImpl(T, S)(S s, in T leftBracket, in T keyval = ":", in T separator = ", ",
930 930
 
931 931
 /// ditto
932 932
 T toImpl(T, S)(S s)
933  
-    if (is(S : Object) &&
  933
+    if (is(S == Object) &&
1
Hara Kenji Collaborator
9rnsr added a note March 12, 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
Hara Kenji
Collaborator
9rnsr commented March 12, 2012

Did you run phobos unit test in your local?

Hara Kenji
Collaborator
9rnsr commented March 12, 2012

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
9rnsr commented March 20, 2012

Ping?

David Herberth

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

Hara Kenji
Collaborator
9rnsr commented April 11, 2012

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

David Herberth

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

Hara Kenji
Collaborator
9rnsr commented April 20, 2012

OK. Changelog conflict is resolved.

Hara Kenji 9rnsr merged commit 803aa7c into from April 20, 2012
Hara Kenji 9rnsr closed this April 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 1 deletion. Show diff stats Hide diff stats

  1. 8  std/conv.d
8  std/conv.d
@@ -930,7 +930,7 @@ T toImpl(T, S)(S s, in T leftBracket, in T keyval = ":", in T separator = ", ",
930 930
 
931 931
 /// ditto
932 932
 T toImpl(T, S)(S s)
933  
-    if (is(S : Object) &&
  933
+    if (is(S == class) &&
934 934
         isSomeString!T)
935 935
 {
936 936
     return toStr!T(s);
@@ -959,6 +959,12 @@ unittest
959 959
     assert(to!string(a) == "null");
960 960
     a = new A;
961 961
     assert(to!string(a) == "an A");
  962
+
  963
+    // Bug 7660
  964
+    class C { override string toString() { return "C"; } }
  965
+    struct S { C c; alias c this; }
  966
+    S s; s.c = new C();
  967
+    assert(to!string(s) == "C");
962 968
 }
963 969
 
964 970
 /// ditto
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.