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

Fix Issue 21753 - Struct literal with function literal member not allowed #12300

Merged
merged 1 commit into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/dmd/dmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,14 @@ public:
}
}

override void visit(FuncExp e)
{
if (e.td)
mangleSymbol(e.td);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tests...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this code only happens inside a struct literal the function type is resolved and e.td is always null.
What should I do? assert(0 or !e.td), comment out, just delete...

else
mangleSymbol(e.fd);
}

////////////////////////////////////////////////////////////////////////////

override void visit(Parameter p)
Expand Down
21 changes: 21 additions & 0 deletions test/compilable/test21753.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// https://issues.dlang.org/show_bug.cgi?id=21753

struct Sample {
int function() func1;
int function() func2;
}

void noth(Sample smpl)() {
static assert(smpl.func1() == 0);
static assert(smpl.func2() == 1);
}

void main() {
enum s = Sample(
{ return 0; },
{ return 1; }
);
static assert(s.func1() == 0);
static assert(s.func2() == 1);
noth!(s)();
}
6 changes: 6 additions & 0 deletions test/runnable/mangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ static assert(funcd.mangleof == "_D6mangle5funcdFPFZNnZi");

/***************************************************/

struct S21753 { void function() f1; }
void fun21753(S21753 v)() {}
alias fl21753 = (){};
static assert((fun21753!(S21753(fl21753))).mangleof == "_D6mangle__T8fun21753VSQv6S21753S1_DQBi10" ~ fl21753.stringof ~ "MFNaNbNiNfZvZQCaQp");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BorisCarvajal: With LDC, I'm somehow getting

actual:   _D6mangle__T8fun21753VSQv6S21753S1f_DQBj10__lambda71MFZvZQBtFNaNbNiNfZv
expected: _D6mangle__T8fun21753VSQv6S21753S1f_DQBj10__lambda71MFNaNbNiNfZvZQCbQp

Any ideas?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lambda on LDC has no attributes ('FZv' instead of 'FNaNbNiNfZv'). Also it misses a backreference because of that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kinke, I found this line to be the cause, it's specific to LDC so I don't know what it really does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx so much!


/***************************************************/
void main()
{
test10077h();
Expand Down