Skip to content
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

[kotlin] K2 J2K: Move VarToValProcessing LocalVarToValInspectionBasedProcessing and fixValToVarDiagnosticBasedProcessing to JKTree #2743

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jocelynluizzi13
Copy link
Contributor

(continuation of #2702 and #2726)

@darthorimar requested that I move the process of determining mutability earlier as it will be faster in the psi/java side of things. However, after completing it in this pull request I feel like this is actually impossible. There are many such cases where the code changes after the JKBuilder phase that would change mutability. For example:

  • testData/newJ2k/issues/kt-19340.java. s1 and s2 are initially stub expressions and are only defined once in the class. This would indicate that they can be val. However, by kt-19340.kt, s1 and s2 are set equal to null initially, and thus have their values changed. There are many more such instances of this.

additionally, per slack discussion we have noted that nameConflict4 and nameConflict5 should be in a run block. However, the j2k is not creating these run blocks, hence those tests failing here.

Thanks in advance for any feedback!

@abelkov @darthorimar @ermattt

@abelkov abelkov added the kotlin Pull requests for Kotlin IntelliJ plugin label Apr 25, 2024
@darthorimar
Copy link
Member

darthorimar commented May 15, 2024

testData/newJ2k/issues/kt-19340.java. s1 and s2 are initially stub expressions and are only defined once in the class.

This case can be handled separately, eg., you can use FinalUtils.canBeFinal instead of FinalUtils.isImmutableField which seems to be handling the case.

additionally, per slack discussion we have noted that nameConflict4 and nameConflict5 should be in a run

Tests seem to be failing because of comparing declarations by name in PsiLocalVariable.toJK(). Please create a new function
HashSet<PsiVariable> calculateVariablesWhichCanBeFinalInBlocks(final PsiCodeBlock body) in LocalCanBeFinal extracting the logic from checkCodeBlockForImmutability.

@jocelynluizzi13
Copy link
Contributor Author

still having an issue with kt-22848 because it is a special case val foo = foo = 5 which doesn't seem to be caught appropriately

also DetectProperties#testInObject is adding a const somewhere that I cannot figure out why

Otherwise, this seems to be working !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kotlin Pull requests for Kotlin IntelliJ plugin
Projects
None yet
3 participants