scala / scala3

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

Inconsistent handling of Union and Intersection types #18565

Open gzoller opened 1 year ago

gzoller commented 1 year ago

Compiler version

3.3.0

Minimized code

  def apply(quotes: Quotes)(aType: quotes.reflect.TypeRepr, typedName: TypedName, resolveTypeSyms: Boolean): RType[_] = 
    import quotes.reflect.*

    val typeRef = aType.asInstanceOf[TypeRef]
    typeRef.classSymbol match {
      case None => 
        typeRef match {
          case AndType(left,right) => ...
        }
      case Some(classSymbol) =>
        typeRef match {
          case OrType(left,right) => ...
        }

Expectation

Union types (OR) are marked with scala.Matchable trait, so they have a classSymbol. Not a very interesting one, but Intersection (AND) types do not have this. So its strange they are handled differently. Previously, both had no classSymbol, and now only one does. Not the end of all things, but this seems like an oversight when Matchable was added to OR. If you add Matchable to AND then it would be consistent again, and you'd be set up for success if ever you want to add behavior to Matchable.

nicolasstucki commented 1 year ago

@gzoller could you provide an example of types that are problematic and a self-contained macro implementation that shows this problem?