diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 53e08fcb707d..bb1606ca8dc6 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -893,11 +893,14 @@ trait Applications extends Compatibility { def realApply(using Context): Tree = { val resultProto = tree.fun match - case Select(New(_), _) if pt.isInstanceOf[ValueType] => pt - // Don't ignore expected value types of `new` expressions. If we have a `new C()` - // with expected type `C[T]` we want to use the type to instantiate `C` - // immediately. This is necessary since `C` might _also_ have using clauses - // that we want to instantiate with the best available type. See i15664.scala. + case Select(New(tpt), _) if pt.isInstanceOf[ValueType] => + if tpt.isType && typedAheadType(tpt).tpe.typeSymbol.typeParams.isEmpty then + IgnoredProto(pt) + else + pt // Don't ignore expected value types of `new` expressions with parameterized type. + // If we have a `new C()` with expected type `C[T]` we want to use the type to + // instantiate `C` immediately. This is necessary since `C` might _also_ have using + // clauses that we want to instantiate with the best available type. See i15664.scala. case _ => IgnoredProto(pt) // Do ignore other expected result types, since there might be an implicit conversion // on the result. We could drop this if we disallow unrestricted implicit conversions. diff --git a/tests/pos/i15802.scala b/tests/pos/i15802.scala new file mode 100644 index 000000000000..ac67f420508c --- /dev/null +++ b/tests/pos/i15802.scala @@ -0,0 +1,13 @@ +sealed trait ZIO[-R, +E, +A] +object ZIO{ + def fail[E](error: E): ZIO[Any, E, Nothing] = ??? +} + +trait Endpoint[INPUT, ERROR_OUTPUT, OUTPUT]{ + sealed trait ZServerEndpoint[R] + def zServerLogic[R](logic: INPUT => ZIO[R, ERROR_OUTPUT, OUTPUT]): ZServerEndpoint[R] = ??? +} + +@main def Test() = + val x: Endpoint[_, Unit, Unit] = ??? + x.zServerLogic[Any](_ => ZIO.fail(new RuntimeException("boom"))) \ No newline at end of file