mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Macros] Always parse macro expansions, diagnose later
Always parse macro expansions, regardless of language mode, and eliminate the fallback path for very, very, very old object literals like `#Color`. Instead, check for the feature flag for macro declaration and at macro expansion time, since this is a semantic restriction. While here, refactor things so the vast majority of the macro-handling logic still applies even if the Swift Swift parser is disabled. Only attempts to expand the macro will fail. This allows us to enable the macro-diagnostics test everywhere.
This commit is contained in:
@@ -5387,27 +5387,21 @@ namespace {
|
||||
}
|
||||
|
||||
Expr *visitMacroExpansionExpr(MacroExpansionExpr *E) {
|
||||
#if SWIFT_SWIFT_PARSER
|
||||
auto &ctx = cs.getASTContext();
|
||||
if (ctx.LangOpts.hasFeature(Feature::Macros)) {
|
||||
auto expandedType = solution.simplifyType(solution.getType(E));
|
||||
cs.setType(E, expandedType);
|
||||
auto expandedType = solution.simplifyType(solution.getType(E));
|
||||
cs.setType(E, expandedType);
|
||||
|
||||
auto locator = cs.getConstraintLocator(E);
|
||||
auto overload = solution.getOverloadChoice(locator);
|
||||
auto locator = cs.getConstraintLocator(E);
|
||||
auto overload = solution.getOverloadChoice(locator);
|
||||
|
||||
auto macro = cast<MacroDecl>(overload.choice.getDecl());
|
||||
ConcreteDeclRef macroRef = resolveConcreteDeclRef(macro, locator);
|
||||
E->setMacroRef(macroRef);
|
||||
auto macro = cast<MacroDecl>(overload.choice.getDecl());
|
||||
ConcreteDeclRef macroRef = resolveConcreteDeclRef(macro, locator);
|
||||
E->setMacroRef(macroRef);
|
||||
|
||||
if (auto newExpr = expandMacroExpr(dc, E, macroRef, expandedType)) {
|
||||
E->setRewritten(newExpr);
|
||||
cs.cacheExprTypes(E);
|
||||
return E;
|
||||
}
|
||||
// Fall through to use old implementation.
|
||||
if (auto newExpr = expandMacroExpr(dc, E, macroRef, expandedType)) {
|
||||
E->setRewritten(newExpr);
|
||||
cs.cacheExprTypes(E);
|
||||
}
|
||||
#endif
|
||||
|
||||
return E;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user