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 picks wrong function #1968

Open
bbannier opened this issue Jan 29, 2025 · 0 comments · May be fixed by #1969
Open

Overload resolution picks wrong function #1968

bbannier opened this issue Jan 29, 2025 · 0 comments · May be fixed by #1969
Assignees
Labels
Bug Something isn't working Compiler

Comments

@bbannier
Copy link
Member

If I implement the same function multiple times for integer types which are coercible into each other, the wrong overload is picked, e.g.,

module foo;

function fn(x: uint8) {
    print "uint8";
}

function fn(x: uint64) {
    print "uint64";
}

global x: uint8 = 0;
fn(x);
$ spicyc -dj foo.spicy
uint64

I would have expected this to print uint8.

Adding a fn taking a string has no effect one these.

It seems we consider overloads with coercible args before we check for explicitly matching ones. We should resolve the correct overload, and also check whether this behaves reasonable for functions taking multiple arguments (where non/some/all require coercions).

@bbannier bbannier added Bug Something isn't working Compiler labels Jan 29, 2025
@rsmmr rsmmr self-assigned this Jan 30, 2025
rsmmr added a commit that referenced this issue Jan 30, 2025
Before, we could unnecessarily coerce integer types when a direct
match was available. The fix takes out the `TryCoercionWithinSameType`
style for non-coercing function call arguments, which solves it. I
don't recall why that was in there in the first place, but it doesn't
seem to break anything to skip it ...

Closes #1968.
@rsmmr rsmmr linked a pull request Jan 30, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants