File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -638,6 +638,9 @@ object Flags {
638638 /** value that's final or inline */
639639 final val FinalOrInline : FlagSet = Final | Inline
640640
641+ /** class that's final or sealed */
642+ final val FinalOrSealed : FlagSet = Final | Sealed
643+
641644 /** A covariant type parameter instance */
642645 final val LocalCovariant : FlagConjunction = allOf(Local , Covariant )
643646
Original file line number Diff line number Diff line change @@ -985,7 +985,11 @@ class Typer extends Namer
985985 case SAMType (sam)
986986 if ! defn.isFunctionType(pt) && mt <:< sam =>
987987 if (! isFullyDefined(pt, ForceDegree .all))
988- ctx.error(ex " result type of closure is an underspecified SAM type $pt" , tree.sourcePos)
988+ ctx.error(ex " result type of lambda is an underspecified SAM type $pt" , tree.sourcePos)
989+ else if (pt.classSymbol.is(FinalOrSealed )) {
990+ val offendingFlag = pt.classSymbol.flags & FinalOrSealed
991+ ctx.error(ex " lambda cannot implement $offendingFlag ${pt.classSymbol}" , tree.sourcePos)
992+ }
989993 TypeTree (pt)
990994 case _ =>
991995 if (mt.isParamDependent) {
Original file line number Diff line number Diff line change 1+ val x : String <:< Int = _.toInt // error
2+
3+ abstract final class Foo { def f (x : Int ): Int }
4+
5+ val foo : Foo = x => x // error
6+
7+ val foo2 : Foo = Predef .identity // error
8+
You can’t perform that action at this time.
0 commit comments