Repository navigation
Overhaul DefaultInitExp - #22903
Overhaul DefaultInitExp#22903
Conversation
|
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#22903" |
Yep, that's a bug fix and a breaking change, will require either an edition guard or a deprecation. |
|
Glad to see this hole finally getting patched! |
e35535d to
22383a6
Compare
|
Test suite looking good, ping me when this is good to go. |
|
So I marked this PR as a refactor, switching from inlineCopy + resolveLoc to syntaxCopy + expressionSemantic. In more detail:
This means less class boilerplate, not having a separate visit pass for if (sc.inDefaultArg || sc.callLoc.isValid)
return false;In a follow up PR I plan to replace these with actual deprecation / edition logic to fix the bug, and add a test and changelog. If this all sounds good, it's ready to merge @thewilsonator |
|
I'll leave it to you to squash or rebase and merge as you see fit. |
Since dlang#22903 (3bedbac) a call takes a `syntaxCopy` of a parameter's default argument and analyzes it in the caller. The stored default argument is already analyzed, and an explicit cast that only repaints its operand's type left no `CastExp` behind: with `enum E : int`, `cast(E) g()` is `g()` typed `E`. The copy then analyzed to an `int`, and the parameter rejected it: void f(E err = cast(E) g()) {} f(); // Error: cannot implicitly convert expression `g()` of type `int` to `E` libasync's `error_t error = cast(EPosix) errno()` is one such default. Convert the analyzed copy to the type the declaration's analysis gave the default argument, which that analysis already checked.
| arg = p.defaultArg.syntaxCopy(); | ||
| { | ||
| Scope* sc2 = sc.push(); | ||
| sc2.callLoc = loc; | ||
| arg = arg.expressionSemantic(sc2); | ||
| sc2.pop(); | ||
| } |
There was a problem hiding this comment.
@dkorpel this introduced a regression when building libasync. Reduced it down to:
enum E : int { a }
int fun();
void test(E e = cast(e) fun()) {}
void main()
{
test();
}I suspect you'll need to reintroduce the original inlineCopy behaviour of just calling copy().
| arg = p.defaultArg.syntaxCopy(); | |
| { | |
| Scope* sc2 = sc.push(); | |
| sc2.callLoc = loc; | |
| arg = arg.expressionSemantic(sc2); | |
| sc2.pop(); | |
| } | |
| arg = p.defaultArg.isDefaultInitExp() ? p.defaultArg.syntaxCopy() : p.defaultArg.copy(); | |
| { | |
| Scope* sc2 = sc.push(); | |
| sc2.callLoc = loc; | |
| arg = arg.expressionSemantic(sc2); | |
| sc2.pop(); | |
| } |
There was a problem hiding this comment.
Ah wait no, ignore my suggestion, it's too shallow a fix as DefaultInitExp may be deeply nested inside the defaultArg.
Big PR, will split off parts but first see how test suite reacts.
Probably fixes (edit: not yet) #18670 (needs tests), supersedes #14309