@@ -108,43 +108,37 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
108
108
case AppliedType (_, funArgs @ fun :: tupled :: Nil ) =>
109
109
def doesFunctionTupleInto (baseFun : Type , actualArgs : List [Type ],
110
110
actualRet : Type , tupled : Type ) =
111
- tupled.dealias =:= constructDependentTupleType(actualArgs, actualRet, defn.isContextFunctionType(baseFun))
111
+ tupled =:= constructDependentTupleType(actualArgs, actualRet, defn.isContextFunctionType(baseFun))
112
112
def doesFunctionUntupleTo (baseFun : Type , actualArgs : List [Type ],
113
113
actualRet : Type , untupled : Type ) =
114
- untupled.dealias =:= untupleDependentTupleType(actualArgs, actualRet, defn.isContextFunctionType(baseFun))
114
+ untupled =:= untupleDependentTupleType(actualArgs, actualRet, defn.isContextFunctionType(baseFun))
115
115
116
116
def functionTypeEqual (baseFun : Type , actualArgs : List [Type ],
117
117
actualRet : Type , expected : Type ) =
118
- expected.dealias =:= defn.FunctionNOf (actualArgs, actualRet, defn.isContextFunctionType(baseFun))
118
+ expected =:= defn.FunctionNOf (actualArgs, actualRet, defn.isContextFunctionType(baseFun))
119
119
def untupleDependentTupleType (args : List [Type ], ret : Type , contextual : Boolean ): Type =
120
120
val methodKind = if contextual then ContextualMethodType else MethodType
121
121
122
-
123
- val p = methodKind(args.indices.map(nme.syntheticParamName).toList)(
122
+ val arity = args.length
123
+ methodKind(args.indices.map(nme.syntheticParamName).toList)(
124
124
mt => args,
125
125
mt =>
126
126
val tpeMap = new TypeMap :
127
127
def apply (tp : Type ): Type =
128
128
tp match
129
- case TermRef (TermParamRef (_, paramNum), name) =>
130
- name match
131
- case x : TermName =>
132
- x.toString match
133
- // hack upon hack upon hack
134
- // please make there be a reverse map so i dont have to do this : (
135
- case s " _ $id" =>
136
- mt.paramRefs(id.toInt)
137
- case _ => ???
138
- case _ => ???
129
+ case defn.TupleSelectorOf (TermParamRef (_, paramNum), fieldNum) =>
130
+ if fieldNum >= arity then
131
+ NoType
132
+ else
133
+ mt.paramRefs(fieldNum)
139
134
case _ => mapOver(tp)
140
135
tpeMap(ret)
141
136
)
142
- p
143
137
144
138
def constructDependentTupleType (args : List [Type ], ret : Type , contextual : Boolean ): Type =
145
139
val methodKind = if contextual then ContextualMethodType else MethodType
146
140
147
- val p = methodKind(List (nme.syntheticParamName(0 )))(
141
+ methodKind(List (nme.syntheticParamName(0 )))(
148
142
mt => List (defn.tupleType(args)),
149
143
mt =>
150
144
val tpeMap = new TypeMap :
@@ -156,35 +150,33 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
156
150
mapOver(tp)
157
151
tpeMap(ret)
158
152
).toFunctionType()
159
- p
160
- val dealiasedFun = fun.dealias
161
- val dealiasedTupled = tupled.dealias
153
+
162
154
val arity : Int =
163
155
if defn.isFunctionNType(fun) then
164
156
// TupledFunction[(...) => R, ?]
165
157
// dont use functionArgInfos it dealiases and drops dependents
166
158
167
- dealiasedFun match
168
- case defn.RefinedFunctionOf (method : MethodType ) if doesFunctionTupleInto(dealiasedFun , method.paramInfos, method.resType, dealiasedTupled ) =>
159
+ fun.dealias match
160
+ case defn.RefinedFunctionOf (method : MethodType ) if doesFunctionTupleInto(fun , method.paramInfos, method.resType, tupled ) =>
169
161
method.paramInfos.size
170
162
// poly types are unsupported
171
163
case defn.RefinedFunctionOf (_) => - 1
172
164
case _ =>
173
165
fun.functionArgInfos match
174
166
case funArgs :+ funRet
175
- if functionTypeEqual(dealiasedFun , defn.tupleType(funArgs) :: Nil , funRet, dealiasedTupled ) =>
167
+ if functionTypeEqual(fun , defn.tupleType(funArgs) :: Nil , funRet, tupled ) =>
176
168
// TupledFunction[(...funArgs...) => funRet, ?]
177
169
funArgs.size
178
170
case _ => - 1
179
171
else if defn.isFunctionNType(tupled) then
180
172
// TupledFunction[?, (...) => R]
181
- dealiasedTupled match
173
+ tupled.dealias match
182
174
case defn.RefinedFunctionOf (method : MethodType ) =>
183
175
method.argInfos match
184
176
case tupledArgs :: funRet :: Nil =>
185
177
// TupledFunction[?, ((...)) => R]
186
178
tupledArgs.tupleElementTypes match
187
- case Some (args) if doesFunctionUntupleTo(dealiasedTupled , args, funRet, dealiasedFun ) =>
179
+ case Some (args) if doesFunctionUntupleTo(tupled , args, funRet, fun ) =>
188
180
args.size
189
181
case _ => - 1
190
182
case _ => - 1
@@ -193,7 +185,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
193
185
case tupledArgs :: funRet :: Nil =>
194
186
// TupledFunction[?, ((...)) => R]
195
187
tupledArgs.tupleElementTypes match
196
- case Some (args) if functionTypeEqual(dealiasedTupled , args, funRet, dealiasedFun ) =>
188
+ case Some (args) if functionTypeEqual(tupled , args, funRet, fun ) =>
197
189
args.size
198
190
case _ => - 1
199
191
case _ => - 1
0 commit comments