Bug 611 – IsExpression fails when inside implemented interface
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2006-11-27T09:57:25Z
Last change time
2018-11-23T23:27:52Z
Keywords
rejects-valid
Assigned to
Walter Bright
Creator
Michael Arntzenius
Comments
Comment #0 by daekharel — 2006-11-27T09:57:25Z
interface Interface(T) {
static assert(is(T : Interface));
}
class Implementor : Interface!(Implementor) {}
-----
The above code generates the following error when compiling:
err.d(2): static assert (is(Implementor : Interface)) is false
The assertion is self-evidently true; Implementor subtypes Interface!(Implementor), so is(Implementor : Interface!(Implementor)) should be true. This error occurs only when the assertion is contained within the interface itself; if it is placed within the Implementor class definition or outside, it compiles.
Please correct me if I'm wrong, but this does not seem incorrect to me. In fact, if the static assert compiles and passes outside the interface, I would think that would be an issue. After all:
interface MyInterface(T) {
static assert(is(T : MyInterface));
}
MyInterface(int) a;
Should compile to :
interface MyInterface(Int) {
static assert(is(int : MyInterface(int));
}
This seems self evidently false to me. An integer does not convert to a MyInterface(int), nor should it. Regardless of where the static assert is, I would think it should fail.
I guess if you have something like:
interface Cloneable(T) {
T clone();
}
then it makes sense to say:
class CloneableObject : Cloneable(CloneableObject) {...}
but I don't think it follows that a Cloneable(CloneableObject) should be convertible back to a plain CloneableObject.
Comment #3 by iamthewilsonator — 2018-11-23T23:27:52Z
2.065.0: Failure with output:
-----
onlineapp.d(8): Error: static assert (is(Implementor : Interface!(Implementor))) is false
onlineapp.d(11): instantiated from here: Interface!(Implementor)
-----
Since 2.066.0: Success and no output