I'm having an issue with overload resolution for n...
# javascript
b
I'm having an issue with overload resolution for nested sealed classes with the same simpleName, in this case
Expression.Access.Variable
and
Pattern.Variable
. Here's some debug output from my testing:
Copy code
visit Variable(name=x)
  > is Expression.Access.Variable: false
  > is Pattern.Variable: true
Matched is Pattern.Variable
  > func = function (p0) { return $boundThis.visit_ta6mxa_k$(p0); }
visit pattern variable: Variable(name=x)
Copy code
visit Variable(qualifier=null, name=x)
  > is Expression.Access.Variable: true
  > is Pattern.Variable: false
Matched is Expression.Access.Variable
  > func = function (p0) { return $boundThis.visit_ta6mxa_k$(p0); }
visit pattern variable: Variable(qualifier=null, name=x)
So, the
is
check of my
when
statement seems to be working fine - it's the actual function
visit(ast: Expression.Access.Variable)
versus
visit(ast: Pattern.Variable)
that's off (via
val func: Type -> T = ::visit
). I'm guessing it's the function resolution, but could be an implementation layer. Continuing to dig around here to see what I can find out. EDIT: Self-contained example in thread.
Here's an example, looks like it's function resolution that's off - both
visit(obj = First.Common())
and
visit(obj = Second.Common())
print
visit(Second.Common), obj = ...
. I'm guessing there's probably not a workaround for this without renaming either the function names or the AST itself.
Copy code
visit(Second.Common), obj = Common(name=First.Common)
visit(First.FirstUnique), obj = FirstUnique(name=First.FirstUnique)
visit(Second.Common), obj = Common(name=Second.Common)
visit(Second.SecondUnique), obj = SecondUnique(name=Second.SecondUnique)
https://gist.github.com/WillBAnders/73b128281de268aac726760d93338fbd
According to a friend this is only an issue for the IR compiler; they couldn't replicate it with the non-IR one.
Update on this, we think this is coming from
NameTables.calculateJsFunctionSignature
, specifically this line that adds argument types to the name. I'm not sure if
it.type.asString()
is supposed to include the entire package name - I'm expecting it should, but that doesn't appear to be the case. I can't get indexing to work locally so I'm not able to track this down too well; can't tell what the type of anything is or where methods are defined. Would like to open a PR for this but not too sure where to start.
Here's the generated output for this; both functions end up with the same name so the second overrides the first.
a
I have no idea what your code does, but to avoid overload resolution for JS, just mark one of the methods with
@JsName("anotherName")
🙌 1
b
Genius, that's exactly the type of workaround I was hoping for - at the very least I don't have to restructure my code for it. Thanks again!