@@ -518,7 +518,7 @@ class ClassfileParser(
518
518
}
519
519
// sigToType
520
520
521
- def parseAnnotArg (skip : Boolean = false )(using ctx : Context , in : DataReader ): Option [untpd.Tree ] = {
521
+ def parseAnnotArg (skip : Boolean = false )(using ctx : Context , in : DataReader ): Option [untpd.Tree | ( Context => untpd. Tree ) ] = {
522
522
523
523
// If we encounter an empty array literal, we need the type of the corresponding
524
524
// parameter to properly type it, but that would require forcing the annotation
@@ -545,20 +545,26 @@ class ClassfileParser(
545
545
case CLASS_TAG =>
546
546
if (skip) None else Some (lit(Constant (pool.getType(index))))
547
547
case ENUM_TAG =>
548
- val enumClassTp = pool.getType (index)
548
+ val sig = pool.getExternalName (index).value
549
549
val enumCaseName = pool.getName(in.nextChar)
550
550
if (skip)
551
551
None
552
552
else {
553
- val enumModuleClass = enumClassTp.classSymbol.companionModule
554
- Some (Select (ref(enumModuleClass), enumCaseName.name))
553
+ val res = (ctx : Context ) => {
554
+ implicit val ctx2 = ctx
555
+ val enumClassTp = sigToType(sig)
556
+ val enumModuleClass = enumClassTp.classSymbol.companionModule
557
+ Select (ref(enumModuleClass), enumCaseName.name)
558
+ }
559
+ Some (res)
555
560
}
556
561
case ARRAY_TAG =>
557
562
val arr = new ArrayBuffer [Tree ]()
558
563
var hasError = false
559
564
for (i <- 0 until index)
560
565
parseAnnotArg(skip) match {
561
- case Some (c) => arr += c
566
+ case Some (c : untpd.Tree ) => arr += c
567
+ case Some (fun : (Context => untpd.Tree ) @ unchecked) => arr += fun(ctx)
562
568
case None => hasError = true
563
569
}
564
570
if (hasError) None
@@ -572,7 +578,13 @@ class ClassfileParser(
572
578
}
573
579
}
574
580
575
- class ClassfileAnnotation (annotType : Type , args : List [untpd.Tree ]) extends LazyAnnotation {
581
+ class ClassfileAnnotation (annotType : Type , lazyArgs : List [untpd.Tree | (Context => untpd.Tree )]) extends LazyAnnotation {
582
+ val args : Context ?=> List [untpd.Tree ] = (using ctx : Context ) =>
583
+ lazyArgs.map {
584
+ case tree : untpd.Tree => tree
585
+ case fun : (Context => untpd.Tree ) @ unchecked => fun(ctx)
586
+ }
587
+
576
588
protected var mySym : Symbol | (Context ?=> Symbol ) =
577
589
(using ctx : Context ) => annotType.classSymbol
578
590
@@ -598,13 +610,19 @@ class ClassfileParser(
598
610
case _ =>
599
611
600
612
val nargs = in.nextChar
601
- val argbuf = new ListBuffer [untpd.Tree ]
613
+ val argbuf = new ListBuffer [untpd.Tree | ( Context => untpd. Tree ) ]
602
614
var hasError = false
603
615
for (i <- 0 until nargs) {
604
616
val name = pool.getName(in.nextChar)
605
617
parseAnnotArg(skip) match {
606
- case Some (arg) => argbuf += untpd.NamedArg (name.name, arg)
607
- case None => hasError = ! skip
618
+ case Some (fun : (Context => untpd.Tree ) @ unchecked) =>
619
+ argbuf += ((ctx : Context ) => untpd.NamedArg (name.name, fun(ctx)))
620
+
621
+ case Some (arg : untpd.Tree ) =>
622
+ argbuf += untpd.NamedArg (name.name, arg)
623
+
624
+ case None =>
625
+ hasError = ! skip
608
626
}
609
627
}
610
628
if (hasError || skip) None
0 commit comments