@@ -42,14 +42,17 @@ class ErasurePreservation extends MiniPhase {
4242 if tr.isRef(defn.BooleanClass ) then TypeA .Boolean else
4343 if tr.symbol.isTypeParam then
4444 def search (tr : TypeRef , depth : Int , outers : List [List [Symbol ]]): TypeA =
45- outers.head.indexOf(tr.symbol) match
46- case - 1 =>
47- search(tr, depth+ 1 , outers.tail)
48- case ind =>
49- if depth != 0 then
50- TypeA .K (depth- 1 , ind)
51- else
52- TypeA .M (ind)
45+ outers.headOption match
46+ case Some (value) => value.indexOf(tr.symbol) match
47+ case - 1 =>
48+ search(tr, depth+ 1 , outers.tail)
49+ case ind =>
50+ if depth != 0 then
51+ TypeA .K (depth- 1 , ind)
52+ else
53+ TypeA .M (ind)
54+ case None =>
55+ TypeA .Ref
5356 search(tr, 0 , outers)
5457 else TypeA .Ref
5558 case _ =>
@@ -70,17 +73,19 @@ class ErasurePreservation extends MiniPhase {
7073 TypeB .M (outers.head.indexWhere(sym => sym.name == tpr.paramName))
7174 case tr : TypeRef if tr.symbol.isTypeParam =>
7275 def search (tr : TypeRef , depth : Int , outers : List [List [Symbol ]]): TypeB =
73- outers.head.indexOf(tr.symbol) match
74- case - 1 =>
75- search(tr, depth+ 1 , outers.tail)
76- case ind =>
77- if depth != 0 then
78- if isConstructor then
79- TypeB .K (depth, ind)
76+ outers.headOption match
77+ case Some (value) => value.indexOf(tr.symbol) match
78+ case - 1 =>
79+ search(tr, depth+ 1 , outers.tail)
80+ case ind =>
81+ if depth != 0 then
82+ if isConstructor then
83+ TypeB .K (depth, ind)
84+ else
85+ TypeB .K (depth- 1 , ind)
8086 else
81- TypeB .K (depth- 1 , ind)
82- else
83- TypeB .M (ind)
87+ TypeB .M (ind)
88+ case None => TypeB .None
8489 search(tr, 0 , outers)
8590 case at : AppliedType if at.tycon.isRef(defn.ArrayClass ) =>
8691 TypeB .Array (toTypeB(at.args.head, outers))
@@ -90,14 +95,16 @@ class ErasurePreservation extends MiniPhase {
9095 def toReturnTypeB (tp : Type , outers : List [List [Symbol ]])(using Context ): TypeB = tp match
9196 case tr : TypeRef if tr.symbol.isTypeParam =>
9297 def search (tr : TypeRef , depth : Int , outers : List [List [Symbol ]]): TypeB =
93- outers.head.indexOf(tr.symbol) match
94- case - 1 =>
95- search(tr, depth+ 1 , outers.tail)
96- case ind =>
97- if depth != 0 then
98- TypeB .K (depth- 1 , ind)
99- else
100- TypeB .M (ind)
98+ outers.headOption match
99+ case Some (value) => value.indexOf(tr.symbol) match
100+ case - 1 =>
101+ search(tr, depth+ 1 , outers.tail)
102+ case ind =>
103+ if depth != 0 then
104+ TypeB .K (depth- 1 , ind)
105+ else
106+ TypeB .M (ind)
107+ case None => TypeB .None
101108 search(tr, 0 , outers)
102109 case at : AppliedType if at.tycon.isRef(defn.ArrayClass ) =>
103110 TypeB .Array (toTypeB(at.args.head, outers))
0 commit comments