Skip to content

Order of the source files changes the compilation result #10634

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

Closed
adpi2 opened this issue Dec 3, 2020 · 4 comments · Fixed by #10925
Closed

Order of the source files changes the compilation result #10634

adpi2 opened this issue Dec 3, 2020 · 4 comments · Fixed by #10925
Milestone

Comments

@adpi2
Copy link
Member

adpi2 commented Dec 3, 2020

While compiling scala3doc I found surprising that the order of the source files change the compilation result.

Minimized code

I minimized it to 3 files.

// Context.scala
trait Context:
  type Symbol

trait SymOps[C <: Context](val c: C):
  extension (sym: c.Symbol):
    def getVisibility(): Int = 0
// Parser.scala
case class Parser(ctx: Context) extends BasicSupport
// BasicSupport.scala
trait BasicSupport:
  self: Parser =>

  object SymOps extends SymOps[ctx.type](ctx)
  export SymOps._

  def parse(sym: ctx.Symbol): Int =
    sym.getVisibility()

Output

BasicSupport.scala Context.scala Parser.scala compiles successfully.

But Parser.scala Context.scala BasicSupport.scala compiles in error:

[info] cannot take signature of (sym: Parser.this.SymOps.c.Symbol)(): Int
[error] -- [E008] Not Found Error: /home/piquerez/lampepfl/dotty-issue/src/main/scala/tasty/BasicSupport.scala:8:8 
[error] 8 |    sym.getVisibility()
[error]   |    ^^^^^^^^^^^^^^^^^
[error]   |    value getVisibility is not a member of BasicSupport.this.ctx.Symbol.
[error]   |    An extension method was tried, but could not be fully constructed:
[error]   |
[error]   |        sym
[error] one error found

Expectation

The order of the source files should not change the compilation result.

@adpi2 adpi2 added the itype:bug label Dec 3, 2020
@adpi2 adpi2 changed the title The order of the source files changes the compilation result Order of the source files changes the compilation result Dec 3, 2020
@adpi2
Copy link
Member Author

adpi2 commented Dec 3, 2020

@b-studios I am not sure this is only a doctool bug since I don't expect the compiler result to depend on the order of the source files. But maybe I am wrong.

@sjrd
Copy link
Member

sjrd commented Dec 3, 2020

Indeed, this is definitely a compiler bug (failing to compile the doctool), not a doctool bug.

@sjrd sjrd removed the area:doctool label Dec 3, 2020
@abgruszecki abgruszecki removed their assignment Dec 3, 2020
@dwijnand
Copy link
Member

dwijnand commented Dec 7, 2020

$ rm *.class *.tasty; scalac3 BasicSupport.scala Context.scala      Parser.scala        # OK
$ rm *.class *.tasty; scalac3 BasicSupport.scala Parser.scala       Context.scala       # OK
$ rm *.class *.tasty; scalac3 Context.scala      BasicSupport.scala Parser.scala        # OK
$ rm *.class *.tasty; scalac3 Context.scala      Parser.scala       BasicSupport.scala  # KO
$ rm *.class *.tasty; scalac3 Parser.scala       BasicSupport.scala Context.scala       # KO
$ rm *.class *.tasty; scalac3 Parser.scala       Context.scala      BasicSupport.scala  # KO

Looks like it's necessary for BasicSupport.scala to precede Parser.scala.

Remembering that the error is in BasicSupport this means that processing Parser before BasicSupport breaks BasicSupport.

@odersky
Copy link
Contributor

odersky commented Dec 26, 2020

With #10902 we get more info:

> sc Context.scala Parser.scala BasicSupport.scala 
cannot take signature of (sym: Parser.this.SymOps.c.Symbol)(): Int

-- [E008] Not Found Error: BasicSupport.scala:9:8 ------------------------------
9 |    sym.getVisibility()
  |    ^^^^^^^^^^^^^^^^^
  |    value getVisibility is not a member of BasicSupport.this.ctx.Symbol.
  |    Extension methods were tried, but the search failed with:
  |
  |        cannot resolve reference to type Parser.this.SymOps.c.type.Symbol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants