Skip to content

Handle multiple type parameter lists in value class methods #23516

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
Jul 14, 2025
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
11 changes: 9 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/VCInlineMethods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import core.*
import Contexts.*, Trees.*, Types.*
import DenotTransformers.*, MegaPhase.*
import ExtensionMethods.*, ValueClasses.*
import Decorators.*


/** This phase inlines calls to methods of value classes.
Expand Down Expand Up @@ -58,12 +59,18 @@ class VCInlineMethods extends MiniPhase with IdentityDenotTransformer {
*/
private def rewire(tree: Tree, mtArgs: List[Tree] = Nil, mArgss: List[List[Tree]] = Nil)
(using Context): Tree =
def noTypeApplyIn(tree: Tree): Boolean = tree match
case _: TypeApply => false
case Apply(fn, _) => noTypeApplyIn(fn)
case _ => true
tree match {
case Apply(qual, mArgs) =>
rewire(qual, mtArgs, mArgs :: mArgss)
case TypeApply(qual, mtArgs2) =>
assert(mtArgs == Nil)
rewire(qual, mtArgs2, mArgss)
if noTypeApplyIn(qual) then
rewire(qual, mtArgs2, mArgss)
else
rewire(qual, mtArgs, mtArgs2 :: mArgss)
case sel @ Select(qual, _) =>
val origMeth = sel.symbol
val origCls = origMeth.enclosingClass
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotc/pos-test-pickling.excludelist
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ parsercombinators-new-syntax.scala
hylolib-deferred-given
hylolib-cb
hylolib
i23266.scala
i23299.scala

# typecheckErrors method unpickling
i21415.scala
21 changes: 6 additions & 15 deletions tests/pos/i23266.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//> using scala 3.7.0

def kek(t: Table, ids: t.Id*) = ???
class Foo(v: Any) extends AnyVal:
def bar[X](bar: X)[Y]: Any = v

trait Table {
type Id = String
}

object Table1 extends Table {
val id: Id = "table1_id"
}

class Table2() extends Table {
val id: Id = "table2_id"
}

val x = kek(Table1, Table1.id)
val y = kek(Table2(), Table2().id)
@main def run: Unit =
val f = new Foo("lol")
println(f.bar[String]("")[Boolean])
17 changes: 17 additions & 0 deletions tests/pos/i23299.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

def kek(t: Table, ids: t.Id*) = ???

trait Table {
type Id = String
}

object Table1 extends Table {
val id: Id = "table1_id"
}

class Table2() extends Table {
val id: Id = "table2_id"
}

val x = kek(Table1, Table1.id)
val y = kek(Table2(), Table2().id)
Loading