scala / scala3

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

Quotes are not checked for override errors / @deprecated usage / @experimental usage #17400

Open smarter opened 1 year ago

smarter commented 1 year ago

Compiler version

3.3.1-RC1-bin-20230502-dee0065-NIGHTLY

Minimized code

import scala.annotation.experimental
import scala.quoted.*

class A:
  def a: Int = 1

def checkOverride(using Quotes) =
  '{
     class Sub extends A:
       def a: String = ""
     new Sub
   }

class B:
  @deprecated def dep: Int = 1

def checkDeprecated(using Quotes) =
  '{
     val b = new B
     b.dep
   }

@experimental class C

def checkExperimental(using Quotes) =
  '{
     println(new C)
   }

Output

No compiler error

Expectation

The fact that we don't check for override errors has weird consequences like in https://github.com/lampepfl/dotty/issues/17398#issuecomment-1533139570.

nicolasstucki commented 1 year ago

The issue is that all the code within quotes is pickled and encoded as a TASTy binary in PickleQuoted. Therefore the AST is never seen by the checking phases.

The solution is to keep both the pickled and non-pickled versions of the AST for more phases. The question is in which structure to retain the original AST.