Skip to content

False "No class, trait or object is defined in the compilation unit." warning when using deferred given #23049

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

Open
eejbyfeldt opened this issue Apr 25, 2025 · 3 comments
Labels
area:incremental-compilation area:reporting Error reporting including formatting, implicit suggestions, etc area:tooling itype:bug

Comments

@eejbyfeldt
Copy link

Compiler version

3.6.4

Minimized code

Compiled with the flag -Yforce-sbt-phases

trait TC[X]
object TC {
  given [X: scala.deriving.Mirror.ProductOf]: TC[X] = ???
}

trait Base[T] {
  given TC[T] = scala.compiletime.deferred
}

case class P()
object A extends Base[P]

Output

No class, trait or object is defined in the compilation unit.
The incremental compiler cannot record the dependency information in such case.
Some errors like unused import referring to a non-existent class might not be reported.

1 warning found

Expectation

The code should compile without warnings.

@eejbyfeldt eejbyfeldt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 25, 2025
@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc area:private options Issues tied to -Y private/internal compiler settings. area:incremental-compilation and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 28, 2025
@Gedochao
Copy link
Contributor

note: -Yforce-sbt-phases is a private flag and thus gives no guarantees.

That being said, it seems the error pops up independently from the option being passed when compiled with Scala CLI + Bloop... so I'm guessing it may be passed implicitly somewhere 🤔

scala-cli compile repro.scala -S 3.nightly
# Compiling project (Scala 3.7.1-RC1-bin-20250425-fb6cc9b-NIGHTLY, JVM (23))
# Warning: No class, trait or object is defined in the compilation unit.
# The incremental compiler cannot record the dependency information in such case.
# Some errors like unused import referring to a non-existent class might not be reported.
# Compiled project (Scala 3.7.1-RC1-bin-20250425-fb6cc9b-NIGHTLY, JVM (23))

the warning goes away when compiled with --server=false

 scala-cli compile repro.scala -S 3.nightly --server=false

and comes back when -Yforce-sbt-phases is passed alongside it.

scala-cli compile repro.scala -S 3.7.nightly --server=false -Yforce-sbt-phases
# No class, trait or object is defined in the compilation unit.
# The incremental compiler cannot record the dependency information in such case.
# Some errors like unused import referring to a non-existent class might not be reported.
# 
# 1 warning found

cc @tgodzik

@eejbyfeldt
Copy link
Author

note: -Yforce-sbt-phases is a private flag and thus gives no guarantees.

I discovered the issue in sbt project (without explicitly using that flag) so my understanding the sbt enable that Phase as part of enabling incremental compilation. I only used that flag to reproduce the issue in a simple single scalafile without involving sbt.

@Gedochao
Copy link
Contributor

Right, so the flag enables the warning (and is an easy way to reproduce with just the compiler script), as it runs the ExtractApi and ExtractDependencies sections... which are also run by zinc via SBT/Bloop.
but the core issue is that this warning shouldn't pop up in those phases in the first place.
so everything's fine regarding the -Yforce-sbt-phases flag, got confused there.

@Gedochao Gedochao added area:tooling and removed area:private options Issues tied to -Y private/internal compiler settings. labels Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:incremental-compilation area:reporting Error reporting including formatting, implicit suggestions, etc area:tooling itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants