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

Conversation

BorisCarvajal
Copy link
Member

… as template value argument

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @BorisCarvajal!

Bugzilla references

Auto-close Bugzilla Severity Description
21753 normal Struct literal with function literal member not allowed as template value argument

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#12300"

@BorisCarvajal
Copy link
Member Author

I forgot user code test case.

@rainers
Copy link
Member

rainers commented Mar 24, 2021

This adds an ambiguity to the grammar (https://dlang.org/spec/abi.html#Value needs an update, too). I tried adding the rule to https://gist.githubusercontent.com/rainers/6cdf73b48837defb9f88/raw/c948888769fc9c83a82eaa5b1069321d090fd303/dmangle.bison

AFAICT the problem is that a mangled name does not have a terminator that is easy to detect.

@Geod24
Copy link
Member

Geod24 commented Mar 24, 2021

AFAICT the problem is that a mangled name does not have a terminator that is easy to detect.

Wouldn't prefixing the symbol with its full length solve this then ?

@rainers
Copy link
Member

rainers commented Mar 24, 2021

If I can trust bison, a prefix character 'f' is good enough.

@BorisCarvajal
Copy link
Member Author

AFAICT the problem is that a mangled name does not have a terminator that is easy to detect.

I did a few test mixing values with lambdas and its backrefs, the end of they were detected correctly but you are expert here, it's always better to make the grammar clean.

@rainers
Copy link
Member

rainers commented Mar 24, 2021

I suspect the ambiguity can happen between the function return type being a struct (mangle starts with an 'S') and a following template parameter being a QualifiedName (starts with an 'S', too).

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...

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!

kinke added a commit to kinke/ldc that referenced this pull request Jun 2, 2021
…riding lambda function type

Introduced in v0.15 (000663e).

Removing this fixes a new test in runnable/mangle.d:
dlang/dmd#12300 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants