@@ -419,10 +419,12 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
419
419
PrettyStackTraceLocation stackTrace (Context, " type-checking-target" ,
420
420
target.getLoc ());
421
421
422
- // First, pre-check the target, validating any types that occur in the
423
- // expression and folding sequence expressions.
424
- if (ConstraintSystem::preCheckTarget (target))
425
- return errorResult ();
422
+ if (!options.contains (TypeCheckExprFlags::AvoidInvalidatingAST)) {
423
+ // First, pre-check the target, validating any types that occur in the
424
+ // expression and folding sequence expressions.
425
+ if (ConstraintSystem::preCheckTarget (target))
426
+ return errorResult ();
427
+ }
426
428
427
429
// Check whether given target has a code completion token which requires
428
430
// special handling. Returns true if handled, in which case we've already
@@ -509,6 +511,11 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
509
511
510
512
auto paramInterfaceTy = paramType->mapTypeOutOfContext ();
511
513
514
+ // Attempt to pre-check expression first, if that fails - skip type-checking.
515
+ // This would make sure that diagnostics about invalid AST are never dropped.
516
+ if (ConstraintSystem::preCheckTarget (defaultExprTarget))
517
+ return Type ();
518
+
512
519
{
513
520
// Buffer all of the diagnostics produced by \c typeCheckExpression
514
521
// since in some cases we need to try type-checking again with a
@@ -531,8 +538,8 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
531
538
// First, let's try to type-check default expression using
532
539
// archetypes, which guarantees that it would work for any
533
540
// substitution of the generic parameter (if they are involved).
534
- if (auto result = typeCheckExpression (
535
- defaultExprTarget, options, &diagnostics)) {
541
+ if (auto result =
542
+ typeCheckTarget ( defaultExprTarget, options, &diagnostics)) {
536
543
defaultValue = result->getAsExpr ();
537
544
return defaultValue->getType ();
538
545
}
0 commit comments