Skip to content

Commit 1b52f09

Browse files
committed
YCheck that returned value conforms to type of the method
1 parent 1a1f878 commit 1b52f09

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ class TreeChecker extends Phase with SymTransformer {
206206
}
207207
}.apply(tp)
208208

209+
210+
override def typedReturn(tree: untpd.Return)(implicit ctx: Context): tpd.Return = {
211+
val ret = super.typedReturn(tree)
212+
val from = if(ret.from.isEmpty) ctx.owner.enclosingMethod else ret.from.symbol
213+
val rType = from.info.finalResultType
214+
assert(ret.expr.tpe <:< rType)
215+
ret
216+
}
217+
209218
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = {
210219
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
211220
assert(tree.isType || !needsSelect(tree.tpe), i"bad type ${tree.tpe} for $tree # ${tree.uniqueId}")

0 commit comments

Comments
 (0)