Skip to content

Commit 8817b38

Browse files
authored
Merge pull request #15866 from dotty-staging/backport-15856
Backport #15856: Ignore prototype only for parameterized new
2 parents d6bea06 + f0d5446 commit 8817b38

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

+8-5
Original file line numberDiff line numberDiff line change
@@ -893,11 +893,14 @@ trait Applications extends Compatibility {
893893

894894
def realApply(using Context): Tree = {
895895
val resultProto = tree.fun match
896-
case Select(New(_), _) if pt.isInstanceOf[ValueType] => pt
897-
// Don't ignore expected value types of `new` expressions. If we have a `new C()`
898-
// with expected type `C[T]` we want to use the type to instantiate `C`
899-
// immediately. This is necessary since `C` might _also_ have using clauses
900-
// that we want to instantiate with the best available type. See i15664.scala.
896+
case Select(New(tpt), _) if pt.isInstanceOf[ValueType] =>
897+
if tpt.isType && typedAheadType(tpt).tpe.typeSymbol.typeParams.isEmpty then
898+
IgnoredProto(pt)
899+
else
900+
pt // Don't ignore expected value types of `new` expressions with parameterized type.
901+
// If we have a `new C()` with expected type `C[T]` we want to use the type to
902+
// instantiate `C` immediately. This is necessary since `C` might _also_ have using
903+
// clauses that we want to instantiate with the best available type. See i15664.scala.
901904
case _ => IgnoredProto(pt)
902905
// Do ignore other expected result types, since there might be an implicit conversion
903906
// on the result. We could drop this if we disallow unrestricted implicit conversions.

tests/pos/i15802.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sealed trait ZIO[-R, +E, +A]
2+
object ZIO{
3+
def fail[E](error: E): ZIO[Any, E, Nothing] = ???
4+
}
5+
6+
trait Endpoint[INPUT, ERROR_OUTPUT, OUTPUT]{
7+
sealed trait ZServerEndpoint[R]
8+
def zServerLogic[R](logic: INPUT => ZIO[R, ERROR_OUTPUT, OUTPUT]): ZServerEndpoint[R] = ???
9+
}
10+
11+
@main def Test() =
12+
val x: Endpoint[_, Unit, Unit] = ???
13+
x.zServerLogic[Any](_ => ZIO.fail(new RuntimeException("boom")))

0 commit comments

Comments
 (0)