digitalmars.D - I don't think this is a bug but...
- Benjamin Shropshire (15/15) Aug 14 2009 The same expression twice gets different results
- Jesse Phillips (2/25) Aug 14 2009 The value of 'b' is assigned during compile time, but since it is indire...
- BCS (4/29) Aug 14 2009 The only other option (beside saying this is correct) would be to make i...
- Jeremie Pelletier (3/36) Aug 14 2009 I don't think this is a good idea, since overload sets can be hijacked t...
- Jeremie Pelletier (2/29) Aug 14 2009 Exactly, when 'b' is declared, Fn(int) isn't declared yet, as it depends...
The same expression twice gets different results code: import std.stdio; bool Fn(float i){ return true; } const bool b = Fn(cast(int)0); static if(b) bool Fn(int i){ return false; } const bool c = Fn(cast(int)0); void main() { writef("%s\n", b); writef("%s\n", c); } output: true false
Aug 14 2009
Benjamin Shropshire Wrote:The same expression twice gets different results code: import std.stdio; bool Fn(float i){ return true; } const bool b = Fn(cast(int)0); static if(b) bool Fn(int i){ return false; } const bool c = Fn(cast(int)0); void main() { writef("%s\n", b); writef("%s\n", c); } output: true falseThe value of 'b' is assigned during compile time, but since it is indirectly called the behavior seems odd. I suppose it is something to be aware of, but it is behaving correctly.
Aug 14 2009
Reply to Jesse,Benjamin Shropshire Wrote:The only other option (beside saying this is correct) would be to make it illegal to add a new function to an overload set after the set is used. That could get very tricky to implement.The same expression twice gets different results code: import std.stdio; bool Fn(float i){ return true; } const bool b = Fn(cast(int)0); static if(b) bool Fn(int i){ return false; } const bool c = Fn(cast(int)0); void main() { writef("%s\n", b); writef("%s\n", c); } output: true falseThe value of 'b' is assigned during compile time, but since it is indirectly called the behavior seems odd. I suppose it is something to be aware of, but it is behaving correctly.
Aug 14 2009
BCS Wrote:Reply to Jesse,I don't think this is a good idea, since overload sets can be hijacked there is nothing that prevents a module from using a local overload set, and another then using it alongside its local hijacks. Having such a "feature" would only limit the programmer in what they can do.Benjamin Shropshire Wrote:The only other option (beside saying this is correct) would be to make it illegal to add a new function to an overload set after the set is used. That could get very tricky to implement.The same expression twice gets different results code: import std.stdio; bool Fn(float i){ return true; } const bool b = Fn(cast(int)0); static if(b) bool Fn(int i){ return false; } const bool c = Fn(cast(int)0); void main() { writef("%s\n", b); writef("%s\n", c); } output: true falseThe value of 'b' is assigned during compile time, but since it is indirectly called the behavior seems odd. I suppose it is something to be aware of, but it is behaving correctly.
Aug 14 2009
Jesse Phillips Wrote:Benjamin Shropshire Wrote:Exactly, when 'b' is declared, Fn(int) isn't declared yet, as it depends on b being true, int is implicitly convertible to float so it matches the first declaration. When 'c' is declared both functions are available and the second declaration is chosen.The same expression twice gets different results code: import std.stdio; bool Fn(float i){ return true; } const bool b = Fn(cast(int)0); static if(b) bool Fn(int i){ return false; } const bool c = Fn(cast(int)0); void main() { writef("%s\n", b); writef("%s\n", c); } output: true falseThe value of 'b' is assigned during compile time, but since it is indirectly called the behavior seems odd. I suppose it is something to be aware of, but it is behaving correctly.
Aug 14 2009