scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.87k stars 1.06k forks source link

REPL completions hide compile error (e.g. Classfile/TASTy is broken error) #18614

Open bishabosha opened 1 year ago

bishabosha commented 1 year ago

Running completions in the REPL seems to ignore any errors produced by the compiler

Compiler version

3.3.0 (to replicate, though im sure the latest version swallows other kinds of errors)

run the repl with JDK 21 (If you use 3.3.1 im sure there is another error that can be swallowed this way)

Minimized code

in the repl, try running completions on this line

scala> import java.lang.reflect.ClassFileFormatVersion.<TAB>

then from now on java.lang.reflect.ClassFileFormatVersion is broken, and no error was printed about the broken class file.

e.g. now mysteriously ClassFileFormatVersion has no members:

scala> java.lang.reflect.ClassFileFormatVersion.RELEASE_21
-- [E008] Not Found Error: -----------------------------------------------------
1 |java.lang.reflect.ClassFileFormatVersion.RELEASE_21
  |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |value RELEASE_21 is not a member of object java.lang.reflect.ClassFileFormatVersion
1 error found

Expectation

I expected to see the same error as if I had not done a completion:

scala> java.lang.reflect.ClassFileFormatVersion.RELEASE_21
error while loading ClassFileFormatVersion,
class file /modules/java.base/java/lang/reflect/ClassFileFormatVersion.class is broken, reading aborted with class java.lang.RuntimeException
bad constant pool index: 0 at pos: 2629
-- [E008] Not Found Error: -----------------------------------------------------
1 |java.lang.reflect.ClassFileFormatVersion.RELEASE_21
  |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |value RELEASE_21 is not a member of object java.lang.reflect.ClassFileFormatVersion
2 errors found
bishabosha commented 8 months ago

just got hit by this again when I tried to do a top level import from a library with incompatible tasty version:

$ scala repl -S 3.3.3 --dep io.github.bishabosha::enhanced-string-interpolator:1.0.1    
Welcome to Scala 3.3.3 (17, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> import stringmatching.regex.Interpolators.<TAB>
!=             ##             ==             asInstanceOf   equals         getClass       hashCode       isInstanceOf   toString

if I use the 1.0.2 version (which changes nothing except tasty version):

$ scala repl -S 3.3.3 --dep io.github.bishabosha::enhanced-string-interpolator:1.0.2
Welcome to Scala 3.3.3 (17, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> import stringmatching.regex.Interpolators.<TAB>
!=                FormatPattern     RSStringContext   equals            isInstanceOf      notifyAll         toString
##                Pattern           asInstanceOf      getClass          ne                r                 unapply
==                PatternElement    eq                hashCode          notify            synchronized      wait
mbovel commented 4 months ago

Skimming through, that seems like a not-so-easy issue to fix, so I add the exp:expert label. Feel free to correct me if I am wrong.