Skip to content
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

Fix failing bounds check on default getter #18419

Merged
merged 1 commit into from
Aug 21, 2023
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ object Applications {
// it's crucial that the type tree is not copied directly as argument to
// `cpy$default$1`. If it was, the variable `X'` would already be interpolated
// when typing the default argument, which is too early.
spliceMeth(meth, fn).appliedToTypes(targs.tpes)
spliceMeth(meth, fn).appliedToTypeTrees(targs.map(targ => TypeTree(targ.tpe).withSpan(targ.span)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this type of confusion occur somewhere else in code, but we just didn't notice it yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the question. By code, do you mean compiler code, or do you mean something about user's code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't clear. I meant in compiler code where we have something like .appliedToTypes(targs.tpes) and actually needs to be constructed with span.

Copy link
Member Author

@dwijnand dwijnand Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I'm aware of. Looking now, perhaps the .appliedToTypes(patternTypes) in quotes pattern should reuse the original pattern tree spans, but I'm not certain. I was thinking Martin would be able to tell if this is a reoccurring problem and how to best deal with it.

case _ => meth
}

Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i18253.orig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import compiletime.ops.int.Max

trait DFSInt[W <: Int]
trait Candidate[R]:
type OutW <: Int
object Candidate:
given [W <: Int, R <: DFSInt[W]]: Candidate[R] with
type OutW = W

def foo[R](rhs: R)(using icR: Candidate[R]): DFSInt[Max[8, icR.OutW]] = ???

object Test:
def check[A](a: A, clue: Int = 1): Unit = ???
val x: DFSInt[8] = ???
check(foo(x))
14 changes: 14 additions & 0 deletions tests/pos/i18253.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import scala.compiletime.ops.int.Max

trait Foo[A]
trait Bar[B]:
type Out <: Int
object Bar:
given inst[C <: Int]: Bar[C] with
type Out = C

class Test:
def mkFoo(using bx: Bar[2]): Foo[Max[1, bx.Out]] = ???
def check[Y](yy: Y, clue: Int = 1): Unit = ()

def test: Unit = check(mkFoo)
Loading