0

考虑以下内容sealed trait

sealed trait Type

object Type {
    case object S
}

sealed trait Test{
    type Tpe <: Type
}

object Test {
    type Aux[T <: Type] = Test{ type Tpe = T }
}

给定一个ClassSymbol表示Test.Aux[S.type]有没有办法得到一个ClassSymbol表示sealed trait Test

4

1 回答 1

0

在挖掘 API 后,我找到了以下解决方案:

def refinedSealedTrait(symbol: Symbols#Symbol): Symbol = {
  if (!symbol.isRefinementClass) {
    return false
  }
  val parents = symbol.parentSymbols
  if (parents.size != 1) {
    return false
  }
  val parentSymbol = parents.iterator.next

  if (parentSymbol.isSealed && parentSymbol.isTrait) {
    parentSymbol
  } else {
    c.abort(...)
  }
}
于 2021-01-14T09:37:27.137 回答