Bug 18960 – Function parameter requires name with default value
Status
RESOLVED
Resolution
INVALID
Severity
trivial
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2018-06-09T10:21:29Z
Last change time
2021-12-05T16:59:17Z
Keywords
bootcamp, pull
Assigned to
No Owner
Creator
Richard Cattermole
Comments
Comment #0 by alphaglosined — 2018-06-09T10:21:29Z
As per spec this should not be possible.
void main() {
Foo foo = &bar;
foo();
}
alias Foo = void function(int=6);
void bar(int v = 6) {
import std.stdio;
writefln("%i", v);
}
A simple error check can be added here:
https://github.com/dlang/dmd/blob/master/src/dmd/parse.d#L2860
Comment #1 by tiberiulepadatu14 — 2019-02-18T13:12:44Z
Hello!
I have written a solution that checks if "ai" is not null at https://github.com/dlang/dmd/blob/master/src/dmd/parse.d#L3014 at if it is, it throws an error; but this creates an error message for the following program:
void main() {
import std.stdio;
writefln("%i", 3);
}
The error is:
/druntime/import/core/internal/traits.d(140): Error: TFunction parameter requires name with default value at == __InoutWorkaroundStruct ai == (null)
/druntime/import/core/internal/traits.d(141): Error: TFunction parameter requires name with default value at == __InoutWorkaroundStruct ai == (null)
From what I have gathered the at is where the type of the parameter is stored.
Why is the line 140 different?
(I am a newcomer so please do not judge the question)
PS: I did not find a solution using the line that you have provided because there are no parameters checked in that line in the parser. Thank you in advance!
Comment #2 by dlang-bot — 2021-12-05T16:36:15Z
@sorin-gabriel updated dlang/dlang.org pull request #3135 "Fix Issue 18960 - Function parameter requires name with default value " fixing this issue:
- fix Issue 18960 - Function parameter requires name with default value
https://github.com/dlang/dlang.org/pull/3135
Comment #3 by alphaglosined — 2021-12-05T16:59:17Z
I am pretty sure I misinterpreted some parts of the spec relating to function parameter declarations. However, I cannot know for certain due to having not linked the part of the spec in question.
Therefore I am closing it as invalid.