| |
| Posted by Daniel Yokomiso | PermalinkReply |
|
Daniel Yokomiso
| Hi,
I've got a really strange bug. I have two modules, bug and bug2, bug2
depends on bug. When I run the compiler I've got an error message.
>dmd bug2 bug -unittest
Internal error: ..\ztc\cgobj.c 3084
If I comment either the pair equality test on bug unittest section, or
the Ordinal template instantiation on bug2, or the clamp template function
on bug, the modules compile fine and executes correctly. This error message
came on other situation, but when I tried to narrow the test case the bug
moved to this place in the modules. The original code is larger, but I think
they're are just symptoms of the same problem. If I compile just bug no
problem occurs.
module bug;
public alias int boolean;
public alias int Order;
public const Order LESS_THAN = -1;
public const Order EQUALS_TO = 0;
public const Order GREATER_THAN = +1;
template Ordinal(T) {
public boolean min(T left, T right) {
return left < right ? left: right;
}
public boolean max(T left, T right) {
return left > right ? left: right;
}
public T clamp(T item, T lower, T upper)
in {
assert(lower <= upper);
} body {
return max(min(item, upper), lower);
}
}
template TPair(T, U) {
public class Pair {
private T _left;
private U _right;
public this(T left, U right) {
this._left = left;
this._right = right;
}
public T left() {
return this._left;
}
public U right() {
return this._right;
}
public boolean eq(Object obj) {
Pair other = cast(Pair) obj;
if (other !== null) {
return (left() == other.left()) && (right() ==
other.right());
} else {
return false;
}
}
}
}
unittest {
instance TPair(char, char) charPair;
charPair.Pair pairA = new charPair.Pair('a', 'b');
charPair.Pair pairB = new charPair.Pair('a', 'b');
assert(pairA == pairB);
printf("Pair tests passed!\r\n");
}
module bug2;
import bug;
instance Ordinal(char) ord;
int main() {
return 0;
}
Best regards,
Daniel Yokomiso.
"All generalizations are false."
|