Skip to content

Weird compilation error about an implicit type is not a valid singleton type, since it is not an immutable path #9290

@NicolasRouquette

Description

@NicolasRouquette

Minimized code

See: https://github.com/NicolasRouquette/lunatech-scala-2-to-scala3-course

// file: package.scala
// If both lines below are commented, then either form of the implicit/extension compiles OK.
// If both lines are uncommented, then the implicit variant fails to compile.
package org.lunatechlabs.dotty
package object sudoku {}
// file: ToplevelDefinitions.scala
package org.lunatechlabs.dotty.sudoku

final case class SudokuField(sudoku: Int)

// This form compiles only when package.scala is commented.
// This form compiles with error when package.scala is uncommented.
implicit class SudokuFieldOps(val sudokuField: SudokuField) extends AnyVal {
  def foo: Int = ???
}

// This form compiles OK regardless of whether package.scala is commented or not.
//extension on (sudokuField: SudokuField) {
//  def foo: Int = ???
//}
## Output

```scala
[error] -- [E083] Type Error: /opt/local/github.dotty/scala2-to-scala3-course.bug/exercises/src/main/scala/org/lunatechlabs/dotty/sudoku/ToplevelDefinitions.scala:7:0 
[error] 7 |implicit class SudokuFieldOps(val sudokuField: SudokuField) extends AnyVal {
[error]   |^
[error]   |org.lunatechlabs.dotty.sudoku.SudokuFieldOps.type is not a valid singleton type, since it is not an immutable path
[error] one error found

Expectation

All 4 variants should compile without any errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions