Bug 12294 – CTFE fails with inherited in contract

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-03T12:04:17Z
Last change time
2020-03-29T16:44:59Z
Keywords
CTFE, pull, rejects-valid
Assigned to
No Owner
Creator
Adam D. Ruppe

Comments

Comment #0 by destructionator — 2014-03-03T12:04:17Z
class Foo { int add(int a) in { assert(a > 0); } body { return a + 10; } } class Bar : Foo { override int add(int a) in { assert(a <= 0 || a > 0); } body { return a + 10; } } void main() { // contracts.d(4): Error: variable a cannot be read at compile time //enum a = new Bar().add(-5); // error enum b = new Foo().add(5); // works } Since both of them are int literals, it seems like it should work in CTFE, and it indeed does with a simple case, but once inheritance gets involved, the contract seems to get confused.
Comment #1 by k.hara.pg — 2014-03-03T18:17:04Z
This is DMD issue.
Comment #2 by k.hara.pg — 2015-07-08T11:47:06Z
Comment #3 by moonlightsentinel — 2020-03-29T16:44:59Z
This code works since 2.086.1.