Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
June 25, 2005 Scalars attributes with similarly named local functions can cause no compile errors. | ||||
---|---|---|---|---|
| ||||
oops! Sorry about the mix up on the last post :( Anyway, I'm already aware that I'm a bug on the planet Earth, yet I'm not subject to any fixing here...but I must say that my wife has been doing a pretty good job on debugging me so far. (Still, I don't think there's anyway a total fix can be applied to me this far into the current life cycle.) :)) Don't mind me...life and application software just seem very similar at this point. # // WinXP SP2 with dmd v0.127 # // Bug: Scalars attributes causing no compile errors, # // when trying to override local functions. # // (Explained a little better below) # // MinMax.d # # private import std.stdio; # private import std.string; # # size_t min(in size_t x, in size_t y) # { if (x > y) return y; else return x; } # # size_t max(in size_t x, in size_t y) # { if (x > y) return x; else return y; } # # size_t length(in char[] s) { return s.length; } # # int main() # { # writefln("min(10, 9)=%d", min(10, 9)); // OK # writefln("max(10, 9)=%d", cast(ulong)max(10, 9)); // OK # writefln("min(10, 9)=%d", cast(long)(.min(10, 9))); // OK # writefln("max(10, 9)=%d", (.max(10, 9))); // OK # # /+ # ' Follow errors occur when casting a function's return value which # ' happens to be spelled exactly the same as a scalars attributes and # ' the local scope function dot (period) is used between them. # ' # ' Errors: # ' found '(' when expecting ',' # ' found ')' when expecting ';' following 'statement' # +/ # writefln("min(10, 9)=%f", cast(real).min(10, 9)); // Won't compile. # writefln("max(10, 9)=%f", cast(real).max(10, 9)); // Won't compile. # // Won't compile. # writefln("length=%d", cast(long).length(toString(min(10,9)))); # # return 0; # } Output: -------- C:\dmd>dmd minmax.d minmax.d(32): found '(' when expecting ',' minmax.d(32): found ')' when expecting ';' following 'statement' minmax.d(33): found '(' when expecting ',' minmax.d(33): found ')' when expecting ';' following 'statement' minmax.d(34): found '(' when expecting ',' minmax.d(34): found ')' when expecting ';' following 'statement' C:\dmd> David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html |
June 25, 2005 Re: Scalars attributes with similarly named local functions can cause no compile errors. | ||||
---|---|---|---|---|
| ||||
Posted in reply to David L. Davis | David L. Davis wrote: > # size_t length(in char[] s) { return s.length; } Why do you even need this? Or is it just something to show the bug with? :) > # writefln("length=%d", cast(long).length(toString(min(10,9)))); Here's your error right here... It should be: # writefln("length=%d", cast(long)(toString(min(10,9)).length)); Or: # writefln("length=%d", cast(long) length(toString(min(10, 9)))); Only thing is, since '.' is supposed to double as the module-scope operator, the first version /should/ work. But I think its trying to call it as a property-function (or whatever we ended up calling these things) rather than a module-function. Oddness. -- Chris Sauls |
June 25, 2005 Re: Scalars attributes with similarly named local functions can cause | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sauls | In article <d9kcvq$30v8$1@digitaldaemon.com>, Chris Sauls says... > >David L. Davis wrote: >> # size_t length(in char[] s) { return s.length; } >Why do you even need this? Or is it just something to show the bug with? :) > Only to show that there's a bug...otherwise the code is pretty useless. :) >> # writefln("length=%d", cast(long).length(toString(min(10,9)))); >Here's your error right here... It should be: ># writefln("length=%d", cast(long)(toString(min(10,9)).length)); > >Or: ># writefln("length=%d", cast(long) length(toString(min(10, 9)))); > >Only thing is, since '.' is supposed to double as the module-scope operator, the first version /should/ work. But I think its trying to call it as a property-function (or whatever we ended up calling these things) rather than a module-function. Oddness. > >-- Chris Sauls Like you pointed out, the module-scope '.' should work even in this code, and this is exactly the error I wanted to point out. I found this error while writing some code where a wrote my own min() function and added a '.' because I had imported std.math, thinking std.math would have it defined as well. But to my surprise std.math doesn't, and the error occured when I tried to compile the code...so I decided that I should take the time to post a simple clear example of the problem. Overwise it may not be found and fixed anytime soon. <g> David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html |
Copyright © 1999-2021 by the D Language Foundation