Skip to content

Fix #4465: Properly call default param getters for nested JS ctors #4502

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

Merged
merged 1 commit into from
Jul 11, 2021

Conversation

gzm0
Copy link
Contributor

@gzm0 gzm0 commented Jun 6, 2021

No description provided.

@gzm0 gzm0 requested a review from sjrd June 6, 2021 12:37
@gzm0 gzm0 linked an issue Jun 6, 2021 that may be closed by this pull request
Comment on lines 1591 to 1595
val allParamsAndInfos = for {
(sym, info) <- allParamSyms.zip(jsParamInfos(sym))
} yield {
genVarRef(sym) -> info
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val allParamsAndInfos = for {
(sym, info) <- allParamSyms.zip(jsParamInfos(sym))
} yield {
genVarRef(sym) -> info
}
val allParamsAndInfos = for {
(paramSym, info) <- allParamSyms.zip(jsParamInfos(sym))
} yield {
genVarRef(paramSym) -> info
}

The double sym on the left and on the right of <- is confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment still stands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also renamed sym to ctorSym. It was confusing me as well :P

if (!trgSym.isLifted)
genLoadModule(trgSym)
else
genNew(trgSym, trgSym.primaryConstructor, captures)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this is incorrect. We could create several instances of the module per enclosing instance, if we use a new every time. We should use the getter method on the enclosing instance instead. If the enclosing instance is a JS class, that means accessing the property of its JSName; if it is a Scala class, it means calling the Scala method with its name and 0 argument.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a side-effect in the constructor of the companion object in the tests, and test that it is only applied once per enclosing instance.

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 7, 2021

Uh oh, this sounds more complicated. Shall we postpone this past 1.6.0?

@sjrd
Copy link
Member

sjrd commented Jun 7, 2021

Yes, let's postpone it.

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix basically LGTM now. I have a few minor comments.

Comment on lines 1591 to 1595
val allParamsAndInfos = for {
(sym, info) <- allParamSyms.zip(jsParamInfos(sym))
} yield {
genVarRef(sym) -> info
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment still stands.

assert(captures.size == 1, "expected exactly one capture")

// Find the module accessor.
val outer = enteringPhase(currentRun.picklerPhase)(trgSym.owner)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does trgSym.originalOwner work? It doesn't require time travel, IIRC.

val name = enteringPhase(currentRun.typerPhase)(trgSym.unexpandedName)

val modAccessor = outer.info.members.lookupModule(name)
val receiver = captures(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val receiver = captures(0)
val receiver = captures.head

?

@gzm0 gzm0 force-pushed the fix-nested-default branch from 73ee9f5 to 491176f Compare July 11, 2021 09:14
@sjrd sjrd merged commit 6c6bbf6 into scala-js:master Jul 11, 2021
@gzm0 gzm0 deleted the fix-nested-default branch July 11, 2021 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default parameters in constructors of nested JS classes cause invalid IR
2 participants