Skip to content

Commit 2d0fe53

Browse files
Merge pull request #23306 from aschwaighofer/fix_dynamic_replacement_undeclared_type_crash
Sema: Fix a crash when checking dynamic replacements on a non existing type
2 parents 7f0d756 + 36e210a commit 2d0fe53

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,8 +2005,9 @@ void lookupReplacedDecl(DeclName replacedDeclName,
20052005
if (!typeCtx)
20062006
typeCtx = cast<ExtensionDecl>(declCtxt->getAsDecl())->getExtendedNominal();
20072007

2008-
moduleScopeCtxt->lookupQualified({typeCtx}, replacedDeclName,
2009-
NL_QualifiedDefault, results);
2008+
if (typeCtx)
2009+
moduleScopeCtxt->lookupQualified({typeCtx}, replacedDeclName,
2010+
NL_QualifiedDefault, results);
20102011
}
20112012

20122013
/// Remove any argument labels from the interface type of the given value that

test/attr/dynamicReplacement.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ extension K {
4646
@_dynamicReplacement(for: init(c:)) // expected-error{{replaced constructor 'init(c:)' is marked as convenience}})
4747
init(rc: Int) { }
4848
}
49+
50+
extension undeclared { // expected-error{{use of undeclared type 'undeclared'}}
51+
@_dynamicReplacement(for: property) // expected-error{{replaced accessor for 'property' could not be found}}
52+
var replacement_property: Int { return 2 }
53+
54+
@_dynamicReplacement(for: func) // expected-error{{replaced function 'func' could not be found}}
55+
func func2() -> Int { return 2 }
56+
}

0 commit comments

Comments
 (0)