Skip to content
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

Method calls should not be allowed on paths #21788

Open
lrytz opened this issue Oct 16, 2024 · 2 comments
Open

Method calls should not be allowed on paths #21788

lrytz opened this issue Oct 16, 2024 · 2 comments

Comments

@lrytz
Copy link
Member

lrytz commented Oct 16, 2024

3.5.1

scala> class A { class B }
scala> def f(using a: A): a.type = { println("f"); a }
scala> given a: A = new A
scala> new f.B
val res0: a.B = A$B@3921135e

Via https://discord.com/channels/632150470000902164/632628489719382036/1296041645900562455

In the quotes API it's a transparent inline def: https://github.com/scala/scala3/blob/3.5.1/library/src/scala/quoted/Quotes.scala#L18.

@sjrd said

I thought that was only allowed for transparent inline defs that inline themselves to a path

which makes sense; is it specced?

@lrytz lrytz added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 16, 2024
@som-snytt
Copy link
Contributor

I'm OK with that, but:

Welcome to Scala 3.5.1 (22.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> class A { class B }
// defined class A

scala> def f(using a: A): a.type = { println("f"); a }
def f(using a: A): a.type

scala> given a[X]: A = new A
def a[X]: A

scala> new f.B
java.lang.AssertionError: assertion failed: val <none>
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArray(BCodeHelpers.scala:151)
        at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:156)
        at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBType(BCodeHelpers.scala:174)

@EugeneFlesselle
Copy link
Contributor

This can also exploited to bypass bound realizability checks:

@main def Test =

  trait A:
    type B >: Int <: Boolean

  def f(using a: A): a.type = a
  given a[X]: A = a

  val _: Boolean = 1 : f.B // ClassCastException

@dwijnand dwijnand removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Oct 16, 2024
@Gedochao Gedochao added area:metaprogramming:quotes Issues related to quotes and splices area:spec area:inline labels Oct 17, 2024
@jchyb jchyb removed the area:metaprogramming:quotes Issues related to quotes and splices label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants