Skip to content

Backport #15856: Ignore prototype only for parameterized new #15866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i15802.scala
Original file line number Diff line number Diff line change
@@ -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")))