-
Notifications
You must be signed in to change notification settings - Fork 396
Fix #3953: mistyping when using PartialFunction with HKT alias #3960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1843,7 +1843,22 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G) | |
} | ||
} | ||
|
||
Some(methodDefWithoutUselessVars) | ||
/* See: https://github.com/scala-js/scala-js/issues/3953 */ | ||
val methodDefWithPatchedTypes = { | ||
val symParamTypes = | ||
if (sym.paramss.isEmpty) Nil | ||
else sym.paramss.head.map(p => toIRType(p.tpe)) | ||
|
||
assert(symParamTypes.length == params.length, | ||
"symParams and vparams have different lengths") | ||
|
||
val patchedParamTypes = collection.mutable.Map( | ||
(params.map(encodeLocalSym(_).name) zip symParamTypes): _*) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use Moreover, and more importantly, we should filter out the parameters for which the IR type is already correct (i.e., the |
||
|
||
patchTypesOfLocals(methodDefWithoutUselessVars, patchedParamTypes) | ||
} | ||
|
||
Some(methodDefWithPatchedTypes) | ||
} | ||
} | ||
} | ||
|
@@ -1906,6 +1921,38 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G) | |
newBody)(methodDef.optimizerHints, None)(methodDef.pos) | ||
} | ||
|
||
private def patchTypesOfLocals(methodDef: js.MethodDef, | ||
patches: mutable.Map[LocalName, ir.Types.Type]) = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be an immutable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it's usually better to explicitly specify the result type of a function that is a bit long, even when it is private. It helps the reader. |
||
|
||
val js.MethodDef(flags, methodName, originalName, params, resultType, body) = | ||
methodDef | ||
|
||
val transformer = new ir.Transformers.Transformer { | ||
override def transform(tree: js.Tree, isStat: Boolean): js.Tree = tree match { | ||
case js.VarRef(ident) => | ||
val patchedTpe = patches.getOrElse(ident.name, tree.tpe) | ||
js.VarRef(ident)(patchedTpe)(tree.pos) | ||
case js.Closure(arrow, captureParams, params, body, captureValues) => | ||
val patchedCaptureValues = captureValues.map(transformExpr(_)) | ||
js.Closure(arrow, captureParams, params, body, patchedCaptureValues)(tree.pos) | ||
6D71 case _ => | ||
super.transform(tree, isStat) | ||
} | ||
} | ||
|
||
val newParams = params.map { | ||
case pd @ ir.Trees.ParamDef(name, originalName, ptpe, mutable, rest) => | ||
val patchedPtpe = patches.getOrElse(name.name, ptpe) | ||
ir.Trees.ParamDef(name, originalName, patchedPtpe, mutable, rest)(pd.pos) | ||
} | ||
|
||
val newBody = body.map(transformer.transform(_, isStat = resultType == jstpe.NoType)) | ||
|
||
js.MethodDef(flags, methodName, originalName, newParams, resultType, | ||
newBody)(methodDef.optimizerHints, None)(methodDef.pos) | ||
} | ||
|
||
|
||
/** Moves all statements after the super constructor call. | ||
* | ||
* This is used for the primary constructor of a non-native JS | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can just use
sym.tpe.params.map(p => toIRType(p.tpe))
.