Skip to content

False reference ambiguity with redundant import and opaque type #14684

@pikinier20

Description

@pikinier20

Compiler version

Reproduced on newest nightly, 3.1.2-RC1, 3.1.2-RC2, 3.0.0

Minimized code

To reproduce this bug, we need three files:

package bar

package baz {
  import util.HTML._

  class TrashRenderer:
      raw("")

}
package bar

package foo {
  import util.HTML._
  import bar.util.HTML._

  object Bazzz:
    raw("asd").toString
}
package bar
package util {
  object HTML:
    opaque type AppliedTag = StringBuilder

    def raw(content: String): AppliedTag = new AppliedTag(content)
    def raw(content: StringBuilder): AppliedTag = content
}

I found out that there are some conditions that must be satisfied for this bug to occur:

  • There must be opaque type in object HTML
  • There must be nested package in the file where the raw method is used so that we can import it by absolute and relative path
  • There must by second usage of raw somewhere

Output

[error] -- [E049] Reference Error: /Users/fzybala/Documents/random/ambiguous-reference-bug/src/main/scala/dotty/tools/scaladoc/tasty/comments/markdown/bug.scala:8:4 
[error] 8 |    raw("asd").toString
[error]   |    ^^^
[error]   |    Reference to raw is ambiguous,
[error]   |    it is both imported by import bar.util.HTML._
[error]   |    and imported subsequently by import bar.util.HTML._

Expectation

Should compile

This problem caused CI to fail on one of my branches in Scaladoc: #14669. Of course double-import is not a good thing but usually compiler knows that it's the same thing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions