Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overload resolution broken if untyped param shares position with typed param in some overload #14827

Open
timotheecour opened this issue Jun 26, 2020 · 2 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Jun 26, 2020

overload resolution broken if untyped param shares position with typed param in some overload.

Example

template fun(a: bool, body: untyped): untyped = discard
template fun(a: int, body: untyped): untyped = discard
template fun(body: untyped): untyped = discard
fun(true, nonexistant) # ok
fun(1, nonexistant) # ok
fun(nonexistant) # Error: undeclared identifier: 'nonexistant'

Current Output

Error: undeclared identifier: 'nonexistant'

Expected Output

works

Additional Information

devel 1.3.5 0327159

seems like the root cause of those:

eg:
#9414 (comment)

This is the documented behaviour, currently overloaded templates must agree on the positioning of untyped parameters. However, there are ideas of how to solve that.

This seems fixable, no?

@timotheecour timotheecour changed the title overload resolution broken if untyped param shares position with typed param overload resolution broken if untyped param shares position with typed param in some overload Jun 26, 2020
@Araq
Copy link
Member

Araq commented Jun 27, 2020

This is actually covered in the spec. But I agree it sucks.

@timotheecour
Copy link
Member Author

as mentioned in #15940 (comment)

in https://nim-lang.github.io/Nim/manual.html#overloading-resolution-lazy-type-resolution-for-untyped says: "But one has to watch out because other overloads might trigger the argument's resolution:"

in the case of this PR, it's fine since each argument is essentially a disguised typed param; maybe that could be the distinction that makes this overloading sane: when untyped params are disguised typed params (undergo semantic analysis), then overloading can happen even if position of untyped params don't match

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants