Skip to content

Spec: Revisit Tuples and Function types. #17941

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

Merged
merged 1 commit into from
Jun 20, 2023

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Jun 7, 2023

[skip ci]

Also add fundamental type aliases for AnyKind, Nothing, & and |.

Also add fundamental type aliases for `AnyKind`, `Nothing`, `&`
and `|`.
@sjrd sjrd requested a review from bishabosha June 20, 2023 07:24
@bishabosha bishabosha merged commit db4befb into scala:main Jun 20, 2023
@sjrd sjrd deleted the spec-functions-and-tuples branch June 20, 2023 13:07
@bishabosha
Copy link
Member

bishabosha commented Jul 10, 2023

I know I did approve this, however in this example I can retrieve a class symbol, parents and members for both scala.Nothing and scala.AnyKind:

import quoted.*

def members[T <: AnyKind: Type](using Quotes): Expr[List[String]] =
  import quotes.reflect.{*, given}
  val cls = TypeRepr.of[T].classSymbol.get
  Expr(cls.memberMethods.map(_.name))

inline def mems[T <: AnyKind] = ${members[T]}

// scala> mems[AnyKind]
// val res0: List[String] = AnyKind has members List()
// scala> mems[Nothing]
// val res1: List[String] = Nothing has members List(hashCode, $isInstanceOf$, !=, equals, ##, isInstanceOf, getClass, ==, $asInstanceOf$, toString, asInstanceOf)

def parents[T <: AnyKind: Type](using Quotes): Expr[String] =
  import quotes.reflect.{*, given}
  val cls = TypeRepr.of[T].classSymbol.get
  Expr(s"${cls.name} has parents: ${TypeRepr.of[T].baseClasses.tail.map(_.name)}")

inline def ps[T <: AnyKind] = ${parents[T]}

// scala> ps[Nothing]
// val res2: List[String] = Nothing has parents: List(Any)
// scala> ps[AnyKind]
// val res3: List[String] = AnyKind has parents: List()

so either Scala 3 reflection is not required to match the spec, or we have to remove this behaviour from reflection (not allowed)

@sjrd
Copy link
Member Author

sjrd commented Jul 10, 2023

IMO those are unforeseen consequences of encoding them as classes in the compiler, not deliberate, intended behavior.

Kordyjan added a commit that referenced this pull request Dec 8, 2023
Backports #17941 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
@Kordyjan Kordyjan added this to the 3.3.2 milestone Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants