Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 13, 2021 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 --- Comment #1 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> --- Looks like there is code to do this when resolving overloads: https://github.com/dlang/dmd/blob/master/src/dmd/dtemplate.d#L1175-L1177 Indeed, the example above works if modified simply by adding an overload: void fun()(float a) {} -- |
May 13, 2021 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 --- Comment #2 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> --- (In reply to Vladimir Panteleev from comment #1) > Indeed, the example above works if modified simply by adding an overload: > > void fun()(float a) {} Oops, never mind that, the compiler just casts int to float. -- |
May 18, 2021 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement -- |
December 17, 2022 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P3 |P4 -- |
October 23 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 Dennis <dkorpel@live.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxsamukha@gmail.com --- Comment #3 from Dennis <dkorpel@live.nl> --- *** Issue 24828 has been marked as a duplicate of this issue. *** -- |
October 23 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 --- Comment #4 from Max Samukha <maxsamukha@gmail.com> --- Why is this marked as enhancement with a low priority? It's a fundumental that doesn't work. -- |
October 23 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 --- Comment #5 from Max Samukha <maxsamukha@gmail.com> --- (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. *fundamental -- |
October 23 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 --- Comment #6 from Nick Treleaven <nick@geany.org> --- > Looks like there is code to do this when resolving overloads: I think that's now in templatesem.d, matchWithInstance: // Shouldn't run semantic on default arguments and return type. foreach (ref param; *tf.parameterList.parameters) param.defaultArg = null; -- |
October 23 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 Dennis <dkorpel@live.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dkorpel@live.nl --- Comment #7 from Dennis <dkorpel@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. -- |
October 23 [Issue 21917] Unused default values for IFTI parameters should not be typechecked against the IFTI-inferred type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21917 --- Comment #8 from Max Samukha <maxsamukha@gmail.com> --- (In reply to Dennis from comment #7) > > This gives an error "foo called with argument types `(string)` matches both ...", showing that default arguments are not considered for overload resolution. Thank you for the explanation! The current semantics makes sense to me now. The fix that strips default arguments doesn't seem the right way to go. What's the reason for this error: void foo(T)(T a = T.init); // Error: undefined identifier `T` void main() { foo(0); foo("x"); foo(); } ? It works with a default argument for the type parameter: void foo(T = int)(T a = T.init); // ok I'd be absolutely happy if this were fixed. -- |
Copyright © 1999-2021 by the D Language Foundation