[Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 23 11:36:59 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=21917
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dkorpel at live.nl
--- Comment #7 from Dennis <dkorpel at live.nl> ---
(In reply to Max Samukha from comment #4)
> Why is this marked as enhancement with a low priority? It's a fundumental
> that doesn't work.
A bug would be if the behavior doesn't follow the spec. The spec says:
> Default parameters are resolved and semantically checked in the context of the function declaration.
After template substitution, this issue's function looks like this:
```
void fun(int value = "hi")
```
In the context of that function, the compiler is correctly issuing an error, so
changing the behavior would be an enhancement.
The lower priority could have been assigned because there's a workaround for
it, I'm not sure. I wouldn't worry too much about it, issues are rarely sorted
by bugzilla priority. The best way to get an issue fixed is to champion it,
raise attention to it, or to work out the fix as detailed as possible so it's
easy to implement.
In this case, one fix would be to lazily evaluate default arguments at the call
site instead of the function declaration site, but that would break semantics
of existing code.
Another fix would be to strip default arguments with semantic errors after
template instantiation. That doesn't look like a breaking change:
```
void foo(T)(T x) {}
void foo(T)(T x = 3) {}
void main()
{
foo("a");
}
```
This gives an error "foo called with argument types `(string)` matches both
...", showing that default arguments are not considered for overload
resolution.
--
More information about the Digitalmars-d-bugs
mailing list