diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 0e7cecb0f360..d619feb966bb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1106,7 +1106,7 @@ class Namer { typer: Typer => mdef match { case mdef: DefDef if mdef.name == nme.ANON_FUN => val hygienicType = avoid(rhsType, paramss.flatten) - if (!(hygienicType <:< tpt.tpe)) + if (!hygienicType.isValueType || !(hygienicType <:< tpt.tpe)) ctx.error(i"return type ${tpt.tpe} of lambda cannot be made hygienic;\n" + i"it is not a supertype of the hygienic type $hygienicType", mdef.pos) //println(i"lifting $rhsType over $paramss -> $hygienicType = ${tpt.tpe}") diff --git a/tests/neg/i3542a.scala b/tests/neg/i3542a.scala new file mode 100644 index 000000000000..b2fe45d75c33 --- /dev/null +++ b/tests/neg/i3542a.scala @@ -0,0 +1,5 @@ +object Foo { + def f()()(implicit ctx: String): Int = ??? + def at[T](op: () => T): Unit = () + at(() => f()) // error: missing () +}