[Sema] Better handle recovery for structurally invalid ReturnStmts

Make sure we preserve the result expression for an out-of-place
`return`, or a non-`nil` result in an initializer. This ensures we
can still provide semantic functionality from them and fixes a crash
where we would fail to type-check a binding.
This commit is contained in:
Hamish Knight
2025-11-05 19:33:19 +00:00
parent ea79f675ff
commit e7f5ca954b
4 changed files with 42 additions and 11 deletions

View File

@@ -179,6 +179,8 @@ return 42 // expected-error {{return invalid outside of a func}}
return // expected-error {{return invalid outside of a func}}
return VoidReturn1() // expected-error {{return invalid outside of a func}}
func NonVoidReturn1() -> Int {
_ = 0
return // expected-error {{non-void function should return a value}}