Bug 2154 – static if (is(typeof(E.toString()) : string)) in template broken

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-06-18T16:51:00Z
Last change time
2015-06-09T01:21:35Z
Keywords
rejects-valid
Assigned to
nobody
Creator
someanon

Comments

Comment #0 by someanon — 2008-06-18T16:51:58Z
This code works fine with v2.013. Both v2.014, v2.015 now errors out. BTW, is there another way to write this code? thanks. $ cat temp.d class V(E) { E[2] data; public /*override*/ string toString() { static if (is(typeof(E.toString()) : string)) { // error line! return ""; } else { string str = ""; return str; } } } class A { public string toString() { return ""; } } typedef V!(A) VA; $ dmd -c temp.d Error: this for toString needs to be type A not type temp.V!(A).V
Comment #1 by 2korden — 2008-08-07T18:35:33Z
Not sure if it is a bug or not. You are trying to access a non-static method. Try one of these solutions: 1) Make the method static: class A { public static string toString() { return ""; } } 2) change your test code: ... static if (is(typeof((new E()).toString()) : string)) { ... Both work for me. Let someone more knowledgeable decide whether we need to close the issue.
Comment #2 by 2korden — 2008-08-07T18:51:05Z
*** Bug 2274 has been marked as a duplicate of this bug. ***
Comment #3 by smjg — 2008-11-24T06:21:02Z
(In reply to comment #1) > Not sure if it is a bug or not. > You are trying to access a non-static method. Try one of these solutions: It is, because the very design of IsExpression is that semantic analysis errors never escape it, but instead cause the IsExpression to evaluate to false.
Comment #4 by clugdbug — 2009-09-04T03:03:43Z
This works now. Not sure when it was fixed, but it was 2.022 or earlier.