File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed 
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
177177   *  check that its staging level matches the current level. 
178178   *  - Static types and term are allowed at any level. 
179179   *  - If a type reference is used a higher level, then it is inconsistent. Will attempt to heal before failing. 
180-    *  - If a term reference is used a different  level, then it is inconsistent. 
180+    *  - If a term reference is used a higher  level, then it is inconsistent. 
181181   * 
182182   *  If `T` is a reference to a type at the wrong level, try to heal it by replacing it with 
183183   *  a type tag of type `quoted.Type[T]`. 
@@ -206,6 +206,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
206206              tryHeal(prefix.symbol, tp, pos)
207207            case  _ => 
208208              mapOver(tp)
209+         case  tp @  TermRef (NoPrefix , _) if  ! tp.symbol.isStatic &&  level >  levelOf(tp.symbol) => 
210+           levelError(tp.symbol, tp, pos)
209211        case  tp : ThisType  if  level !=  - 1  &&  level !=  levelOf(tp.cls) => 
210212          levelError(tp.cls, tp, pos)
211213        case  tp : AnnotatedType  => 
Original file line number Diff line number Diff line change 1+ //>  using  scala  " 3.2.1" 
2+ import  scala .quoted .Expr 
3+ import  scala .quoted .Type 
4+ import  scala .quoted .quotes 
5+ import  scala .quoted .Quotes 
6+ 
7+ object  macros  {
8+ 
9+   inline  transparent  def  mkNames [A ]:  List [Any ] =  $ { mkNamesImpl[A ] }
10+ 
11+   def  mkNamesImpl [A :  Type ](using  Quotes ):  Expr [List [Any ]] =  {
12+     import  quotes .reflect ._ 
13+ 
14+     val  fieldNames  =  TypeRepr .of[A ].typeSymbol.declaredFields.map(_.name)
15+ 
16+     val  types  =  fieldNames
17+       .map { f => 
18+         val  t1  =  ConstantType (StringConstant (f))
19+         t1.asType match  {
20+           case  ' [t1Type] =>  TypeRepr .of[(t1Type, " aa"  )]
21+         }
22+       }
23+       .reduceLeft[TypeRepr ](OrType (_, _))
24+ 
25+     types.asType match  {
26+       case  ' [ttt] => 
27+         Expr .ofList[ttt](
28+           fieldNames.map { v => 
29+             Expr [(v.type , " aa"  )](v ->  " aa"  ).asExprOf[ttt] //  error
30+           }
31+         )
32+     }
33+   }
34+ 
35+ }
Original file line number Diff line number Diff line change 1+ import  scala .quoted ._ 
2+ def  test (v : String )(using  Quotes ):  Any  = 
3+   Type .of :  Type [v.type ] //  error
4+   Type .of[v.type ] //  error
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments