Getting TermRef of a value

I have a function in my macros:

def makeTupleType(using Quotes)(items: List[Key]): TypeRepr =
  import quotes.reflect.*
  val typeRefs = items.map { item =>
    val path = "me.chuwy.Example.Namespace.Key.$item"
    Symbol.requiredModule(path).termRef   // Tried different variations
  }
  defn.TupleClass(typeRefs.length).typeRef.dealias.appliedTo(typeRefs)  // works for 1+ arity

All Keys are elements of an enum:

package me.chuwy

object Example:
  object Namespace:
    enum Key:
      case One
      case Two
      case Three

What I want in the end is something like Tuple2[One.type, Three.type], but the problem is that I cannot find a way for a Symbol to find the TermRef - the best I could get is Tuple2[Key, Key]. How do I get TermRefs for enum cases?

This works, but I couldn’t make a demo really because im not sure how you are using this method

def makeTupleType(using Quotes)(items: List[Key]): quotes.reflect.TypeRepr =
  import quotes.reflect.*
  val KeyObj = TypeRepr.of[Key.type].classSymbol.get
  val typeRefs = items.map { item =>
    KeyObj.memberField(s"$item").termRef
  }
  defn.TupleClass(typeRefs.length).typeRef.dealias.appliedTo(typeRefs)

Hey, thanks @bishabosha. But unfortunately it did not work.

I wrote a simple macro that shows TermRef ASTs:

  private def checkImpl[T: Type](using Quotes) =
    import quotes.reflect.*

    println(TypeRepr.of[T])      
    '{ () }
check[Example.Key]
TypeRef(TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object skunk),object tables),object ColumnSelect),object Example),class Key)
                                                                                                                                                      
check[Example.Key.One.type]
TermRef(TermRef(TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object skunk),object tables),object ColumnSelect),object Example),object Key),val One)

Second case ends with:

object Example, object Key, val One

But if I use your function - the resulting AST ends with:

module class Example$, module class Key$, val One

I’m basically stuck with classes in the path. I can make Example an object, but as soon as I call fieldMember - Example becomes a class. Tried companionModule, but it gives the same result.

Ok, actually it seems the problem was in a different place. Just my code was not compiling without sensible errors and everything pointed to this macro - solved it now. Thank you very much!