Skip to content

Commit 16aee65

Browse files
authored
Merge pull request #9323 from dotty-staging/fix-#9290
Fix #9290: Insert correct package object for overloaded definitions
2 parents 4477847 + 8074b8a commit 16aee65

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,13 @@ object TypeOps:
461461
def makePackageObjPrefixExplicit(tpe: NamedType)(using Context): Type = {
462462
def tryInsert(pkgClass: SymDenotation): Type = pkgClass match {
463463
case pkg: PackageClassDenotation =>
464-
val pobj = pkg.packageObjFor(tpe.symbol)
464+
var sym = tpe.symbol
465+
if !sym.exists && tpe.denot.isOverloaded then
466+
// we know that all alternatives must come from the same package object, since
467+
// otherwise we would get "is already defined" errors. So we can take the first
468+
// symbol we see.
469+
sym = tpe.denot.alternatives.head.symbol
470+
val pobj = pkg.packageObjFor(sym)
465471
if (pobj.exists) tpe.derivedSelect(pobj.termRef)
466472
else tpe
467473
case _ =>

tests/pos/i9290/Test.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package sudoku
2+
3+
final case class SudokuField(sudoku: Int)
4+
5+
// This form compiles only when package.scala is commented.
6+
// This form compiles with error when package.scala is uncommented.
7+
implicit class SudokuFieldOps(val sudokuField: SudokuField) extends AnyVal {
8+
def foo: Int = ???
9+
}

tests/pos/i9290/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package object sudoku {}

0 commit comments

Comments
 (0)