Skip to content

Commit 16ad84e

Browse files
committed
Fix returns inside while cycles.
typing of Returns looked for directly enclosing method, but didn't take in account presence of synthesised labels. So if one had a return inside a while loop it would be adapted to type of while, which is always unit. The adaption always succeeds and it was left unnoticed.
1 parent 981a218 commit 16ad84e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
677677
if (cx == NoContext || owner.isType) {
678678
ctx.error("return outside method definition", tree.pos)
679679
(EmptyTree, WildcardType)
680-
} else if (owner.isSourceMethod)
680+
} else if (owner.isSourceMethod && !(owner is Flags.Label))
681681
if (owner.isCompleted) {
682682
val from = Ident(TermRef(NoPrefix, owner.asTerm))
683683
val proto = returnProto(owner)

0 commit comments

Comments
 (0)