Generating a match case with wildcard types #19325
Unanswered
adamw
asked this question in
Metaprogramming
Replies: 2 comments 2 replies
-
I'm pretty sure the lower bound comes first and the higher bound comes second: TypeBounds(TypeRepr.of[Nothing], TypeRepr.of[Any]) |
Beta Was this translation helpful? Give feedback.
2 replies
-
Not sure what was wrong with the original one, but this one works: myTypeRepr.classSymbol match
case Some(sym) if myTypeRepr.typeArgs.nonEmpty => // is generic
val wildcardTypeParameters: List[Tree] =
List.fill(orType.typeArgs.length)(TypeBoundsTree(TypeTree.of[Nothing], TypeTree.of[Any]))
Some(CaseDef(Typed(Wildcard(), Applied(TypeIdent(sym), wildcardTypeParameters)), None, caseThen)) this variant is based on the output of printing the tree for Inlined(None, Nil, Block(Nil, Match(Ident("Nil"), List(CaseDef(Typed(Wildcard(), Applied(TypeIdent("List"), List(TypeBind(_$1, TypeBoundsTree(TypeIdent("Nothing"), TypeIdent("Any")))))), None, Block(Nil, Literal(UnitConstant()))))))) I don't have the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
given a
TypeRepr
which represents an applied generic type such asList[String]
, I'd like to generate a match case:(to avoid unchecked warnings). I've got this working for non-generic types, but the wildcards pose a problem. Here's what I got so far:
However, this leads to a compile-time error:
In other cases I'm using
Typed(Wildcard(), TypeIdent(sym))
, so I suspect this must be something withwildcardTypeParameters
, but I'm a bit stuck trying to find exactly what.Or maybe I'm trying to approach this wrong the wrong angle?
Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions