@@ -419,10 +419,12 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
419419 PrettyStackTraceLocation stackTrace (Context, " type-checking-target" ,
420420 target.getLoc ());
421421
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+ }
426428
427429 // Check whether given target has a code completion token which requires
428430 // special handling. Returns true if handled, in which case we've already
@@ -509,6 +511,11 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
509511
510512 auto paramInterfaceTy = paramType->mapTypeOutOfContext ();
511513
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+
512519 {
513520 // Buffer all of the diagnostics produced by \c typeCheckExpression
514521 // since in some cases we need to try type-checking again with a
@@ -531,8 +538,8 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
531538 // First, let's try to type-check default expression using
532539 // archetypes, which guarantees that it would work for any
533540 // 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)) {
536543 defaultValue = result->getAsExpr ();
537544 return defaultValue->getType ();
538545 }
0 commit comments