Skip to content

Unchecked overrides in quoted expressions unless expanded #15700

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
prolativ opened this issue Jul 18, 2022 · 1 comment
Open

Unchecked overrides in quoted expressions unless expanded #15700

prolativ opened this issue Jul 18, 2022 · 1 comment
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:enhancement

Comments

@prolativ
Copy link
Contributor

Compiler version

3.2.1-RC1-bin-20220717-5c43324-NIGHTLY and before

Minimized code

MacroOverride.scala:

//> using scala "3.2.1-RC1-bin-20220717-5c43324-NIGHTLY"

import scala.quoted.*

trait Foo:
  def xxx: Int

inline def foo(inline cond: Boolean) = ${ fooImpl('cond) }

def fooImpl(cond: Expr[Boolean])(using Quotes) =
  if cond.valueOrAbort then
    '{
      new Foo {
        override def xxx = 2
      }
    }
  else
    '{
      new Foo {
        override def xxxx = 1
      }
    }

MacroOverrideTest.scala:

val f = foo(true)

Output

No error

Expectation

The compiler should complain about the implementation of Foo in the else branch - it doesn't implement xxx and overrides xxxx, which doesn't exist in Foo. Currently one only gets the error if the quoted expression with the invalid implementation actually gets expanded, e.g. if one invokes foo(false)

@prolativ prolativ added itype:bug area:metaprogramming:quotes Issues related to quotes and splices labels Jul 18, 2022
@nicolasstucki
Copy link
Contributor

These checks are done in the transformPhases of the compiler. But by then the contents of the quote are pickled. We would need to perform them before pickling.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 12, 2023
This enables the checking phases to analyze the contents of quoted
expression.

Fixes scala#15700
Fixes scala#17400
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 17, 2023
This enables the checking phases to analyze the contents of quoted
expression.

Fixes scala#15700
Fixes scala#17400
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 6, 2023
This enables the checking phases to analyze the contents of quoted
expression.

Fixes scala#15700
Fixes scala#17400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants