Skip to content
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

Incremental compiler fails when type parameter in trait is inferred #22651

Open
Anghammar opened this issue Feb 24, 2025 · 3 comments
Open

Incremental compiler fails when type parameter in trait is inferred #22651

Anghammar opened this issue Feb 24, 2025 · 3 comments

Comments

@Anghammar
Copy link

Compiler version

3.6.3

Minimized code

File 1:

object IncrementalCompilerBug {
  import IncrementalCompilerBugOtherFile.Foo
  val x: Foo.InnerTrait = Foo.ExplicitTypeParameter
  val y: Foo.InnerTrait = Foo.TypeParameterFromInference
}

File 2:

object IncrementalCompilerBugOtherFile {
  trait SuperTrait {
    trait InnerTrait
    trait TraitWithTypeParameter[A](a: A) extends InnerTrait
  }
  object Foo extends SuperTrait {
    object ExplicitTypeParameter extends TraitWithTypeParameter[Int](3)
    object TypeParameterFromInference extends TraitWithTypeParameter(3)
  }
}

Output

Found:    IncrementalCompilerBugOtherFile.Foo.TypeParameterFromInference.type
Required: IncrementalCompilerBugOtherFile.Foo.InnerTrait [4:27]

Expectation

File 1 and 2 compiles just fine when you compile them both, e.g. when doing clean and compile in SBT. However, doing any irrelevant change in file 1 (like adding a comment or whitespace) without touching file 2 and recompiling with SBT will result in the compilation failure above at val y since TypeParameterFromInference extends TraitWithTypeParameter using type inference. In comparison, the compiler never have any problem with val x.

@Anghammar Anghammar added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 24, 2025
@Gedochao Gedochao added area:sbt-bridge area:tooling and removed area:sbt-bridge stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 24, 2025
@Gedochao
Copy link
Contributor

I managed to reproduce it with SBT, but it doesn't occur with Scala CLI.
Seems to be SBT-specific.

@Gedochao
Copy link
Contributor

@adpi2 any clue?

@som-snytt
Copy link
Contributor

It reproduces for me with separate compilation (second file first).

➜  i22651 ~/projects/dotty/bin/scalacQ -d ~/sandbox b.scala
➜  i22651 ~/projects/dotty/bin/scalacQ -d ~/sandbox -cp ~/sandbox a.scala
-- [E007] Type Mismatch Error: a.scala:5:30 ------------------------------------
5 |  val y: Foo.InnerTrait = Foo.TypeParameterFromInference
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |Found:    IncrementalCompilerBugOtherFile.Foo.TypeParameterFromInference.type
  |Required: IncrementalCompilerBugOtherFile.Foo.InnerTrait
  |
  | longer explanation available when compiling with `-explain`
1 error found
➜  i22651

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

No branches or pull requests

3 participants