March 08, 2013 [Issue 5906] Just pre-conditions at compile-time when arguments are static | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=5906 --- Comment #10 from bearophile_hugs@eml.cc 2013-03-07 19:25:12 PST --- (In reply to comment #9) > struct S(int a) > { > void fun(int b) in { assert(a != b); } body {} > } > > void main() > { > foreach(i; TypeTuple!(1, 2, 3, 4)) > { > auto s = S!i(); > if (i != 4) > s.fun(4); > } > } > > This code would error 'cannot call S.fun with b == 4' etc even though S.fun never actually gets called with 4. I see, thank you for the answer. If the pre-condition analysis (constant folding) is done after a normal step of dead branch removal, then maybe that error will not be shown. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 08, 2013 [Issue 5906] Just pre-conditions at compile-time when arguments are static | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=5906 --- Comment #11 from bearophile_hugs@eml.cc 2013-03-07 19:29:40 PST --- (In reply to comment #10) > If the pre-condition analysis (constant folding) is done after a normal step of dead branch removal, then maybe that error will not be shown. Currently it doesn't happen, and this generates an error (you need a "static if" to make the error go away): import std.typetuple; void main() { int[4] a; foreach (i; TypeTuple!(1, 2, 3, 4)) { if (i != 4) a[i]++; } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 08, 2013 [Issue 5906] Just pre-conditions at compile-time when arguments are static | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=5906 --- Comment #12 from yebblies <yebblies@gmail.com> 2013-03-08 14:33:58 EST --- (In reply to comment #10) > > I see, thank you for the answer. > If the pre-condition analysis (constant folding) is done after a normal step of > dead branch removal, then maybe that error will not be shown. > Currently it doesn't happen, and this generates an error (you need a "static if" to make the error go away): That is an interesting point. I seriously doubt that would be enough anyway, I think you would need full flow analysis to work out which paths can actually be taken. Another good example is this: int div(int a, int b) in { assert(b != 0, "Division by zero!"); } body { return a / b; } void main(string[] args) { auto i = 3 / 0; // Fails at compile time auto j = div(3, 0); // Would fail at compile time if this was implemented } So maybe it is acceptable. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation