v66: Overloading Error
Monkey Forums/Monkey Programming/v66: Overloading Error
| ||
Edit: Confirmed the bug on v68, look at the next post for a very compact example of the bug. There's some very strange bug that's causing this overload to fail. "Error : Unable to determine overload to use: Function Bug:object(Local obj:object,Local value:Int) or Function Bug:object(Local obj:object,Local value:String)" Edit: If I change line 10 to [monkeycode]Bug(Object(Self), test)[/monkeycode] then the code works. Although the error had nothing to do with that and the behavior seems incorrect since I've been able to use Self before in a function and not have issues. |
| ||
I just came to this issue again but it was on a smaller scale which helped me make a much tinier example. Also, this is using monkey v68.Function Main() Bug(New StringList(), 1) End Function Bug( obj:Object, value:Int ) End Function Bug( obj:Object, value:String ) End Unable to determine overload to use: Function Bug:Int(Local obj:object,Local value:Int) or Function Bug:Int(Local obj:object,Local value:String). |
| ||
This is correct according to Monkey... * If an overloaded version is found that is an exact match for the number and type of function call parameters, that version is used. * Otherwise, if there is exactly one overloaded version that can be called by implicitly converting the function call parameters, that version is used. * Otherwise, an error is generated. Both 'Bug' overloads require an implicit conversion (ie: at least an upcast of the first parameter to 'object') and neither is an exact match so an error is generated. More sophisticated overload matching logic could deal with this, but I don't plan on doing that any time soon so you'll have to cast params to object (or, add overloads that are exact matches). |
| ||
Hmm? This starts getting weird when there's things like this and this is why I filed this as a bug report... This works. Function Main:Int() Bug(New StringList(), 1) End Function Bug( obj:Object, val:Bool ) End Function Bug( obj:Object, val:Int ) End This does not work. Function Main:Int() Bug(New StringList(), True) End Function Bug( obj:Object, val:Bool ) End Function Bug( obj:Object, val:Int ) End It's inconsistent behavior that I would think is considered a bug or at least they should both return the same error. |
| ||
Yep, that *is* weird - should be causing an error. Will take a look... [edit] Nope, that works. There is no implicit conversion from int to bool, so there is only one possible match. [/edit] |
| ||
I fixed this bug in v78a/b/c/d. It made no sense to have ToString cause a cast to string when a parameter had object as a type that could be given. In trans/decl.monkey line 541, I changed it from... If exprTy.EqualsType( declTy ) Continue to If exprTy.EqualsType( declTy ) Continue Local declClass:ClassDecl, parentClass:ClassDecl, found:Bool declClass = declTy.GetClass() If exprTy.GetClass() <> Null Then parentClass = exprTy.GetClass().superClass While parentClass <> Null If parentClass = declClass found = True Exit End parentClass = parentClass.superClass End If found Then Continue Edit: I tested it quite a bit, it definitely seems fixed. Casting is still done where appropriate and it no longer confuses types. I actually thought this would only fix the object casting problem, but I was wrong. It seems to fix everything. Edit: I made a pull request here under issue 55. |