scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.89k 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 9 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 5 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.

SethTisue commented 3 weeks ago

@mbovel is it valid to have both "exp:expert" and "Spree" — like a spree team with an expert — or should "Spree" be removed?

mbovel commented 3 weeks ago

is it valid to have both "exp:expert" and "Spree"

Yes, it's a reminder for me that I should only assign this issue to a team with an experienced contributor.

mbovel commented 3 weeks ago

This issue was picked for the Scala Issue Spree of Monday, November 11th. @dwijnand and @jan-pieter will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

jan-pieter commented 2 weeks ago

We have reproduced the issue. We think there are 2 causes:

  1. Tab completion seems to hide all compiler output
  2. Errors during the parsing of the tasty & class files are only emitted only once (probably because the results are cached even if it fails)

The result of this combination is that the user doesn't see the error when it happens first during tab completion.

There are 2 possible fixes:

  1. Do show (some) errors during tab completion
  2. Do not cache the result of class/tasty file parsing failures when using the compiler in interactive mode