Skip to content

Check private access at resolution, not an invocation #13392

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 35 commits into from
Jul 21, 2025

Conversation

Akirathan
Copy link
Member

@Akirathan Akirathan commented Jun 27, 2025

Fixes #13078

Pull Request Description

Previously, runtime privacy checking did not respect lexical scope. This change moves the privacy checks into UnresolvedSymbol.resolveFor, where the project of the UnresolvedSymbol's scope is compared to the project where the target function is defined.

In other words, private access is checked at resolution (which happens at runtime, before a method is invoked), not at invocation.

Important Notes

Workarounds introduced in 08b04dd reverted in:

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@Akirathan Akirathan self-assigned this Jun 27, 2025
@Akirathan Akirathan added the CI: No changelog needed Do not require a changelog entry for this PR. label Jun 27, 2025
@Akirathan Akirathan changed the title Wip/akirathan/13078 private generated getters Minor fixes for private method calls Jul 1, 2025
@Akirathan Akirathan marked this pull request as ready for review July 1, 2025 11:14
Copy link
Contributor

@GregoryTravis GregoryTravis left a comment

Choose a reason for hiding this comment

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

Looks good. Just one question about being able to access a field of a public constructor of a private type.

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

  • looks like the names of the test methods are/were incorrect
  • the title needs a change
    • looking at the CI failures, this is not going to be minor
    • I suggest one such title
  • a change log entry might be needed

@@ -20,17 +20,14 @@ add_specs spec_builder =
group_builder.specify "can get on hold of private constructor" <|
Public_Type.cons . is_nothing . should_be_false

group_builder.specify "cannot directly call private constructor" <|
Test.expect_panic Private_Access <| Public_Type.cons 42
Copy link
Member

Choose a reason for hiding this comment

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

  • This test was clearly wrong - calling public static method Public_Type.cons is certainly allowed
  • again the name of the test was misleading - cons is a method, not a constructor

@JaroslavTulach JaroslavTulach changed the title Minor fixes for private method calls Check private access at resolution, not an invocation Jul 6, 2025
@JaroslavTulach
Copy link
Member

JaroslavTulach commented Jul 16, 2025

  INFO ide_ci::program::command: sbt ℹ️ [error] Test org.enso.interpreter.test.privateaccess.PrivateCheckDisabledTest.privateCtorCanBeAccessedWhenPrivateCheckIsDisabled failed: org.graalvm.polyglot.PolyglotException: Private_Access.Error, took 0.042 sec
 INFO ide_ci::program::command: sbt ℹ️ [error]     at <enso>.Main.main(Main.enso:3)
 INFO ide_ci::program::command: sbt ℹ️ [error]     at org.graalvm.polyglot.Value.execute(Value.java:1047)
 INFO ide_ci::program::command: sbt ℹ️ [error]     at org.enso.polyglot.Function.execute(Function.scala:19)
 INFO ide_ci::program::command: sbt ℹ️ [error]     at org.enso.test.utils.ProjectUtils.testProjectRun(ProjectUtils.java:134)
 INFO ide_ci::program::command: sbt ℹ️ [error]     at org.enso.test.utils.ProjectUtils.testProjectRun(ProjectUtils.java:89)
 INFO ide_ci::program::command: sbt ℹ️ [error]     at org.enso.interpreter.test.privateaccess.PrivateCheckDisabledTest.privateCtorCanBeAccessedWhenPrivateCheckIsDisabled(PrivateCheckDisabledTest.java:37)
 INFO ide_ci::program::command: sbt ℹ️ [error]     at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
 INFO ide_ci::program::command: sbt ℹ️ [error]     at java.lang.reflect.Method.invoke(Method.java:565)

❌ prevent getting value from private constructor
Expected an error Private_Access but no error occurred, instead got: (Cons 42) (at Base_Tests/src/Semantic/Meta_Spec.enso:109:13-73).
❌ prevent getting value from constructor in private module
Expected an error Private_Access but no error occurred, instead got: (Cons 42) (at Base_Tests/src/Semantic/Meta_Spec.enso:120:13-73).

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

  • return back the code that had to be changed to lambdas in #13047
  • having the access checks in UnresolvedSymbol seems correct
  • please add .name test

# allow us to do that easily.
# For more info, see https://github.com/enso-org/enso/issues/6729
group_builder.specify "can get reference to private constructor, but cannot call it" <|
group_builder.specify "can get reference to private constructor, and call it from different project" <|
cons_fn data = Public_Type.cons data
Copy link
Member

@JaroslavTulach JaroslavTulach Jul 16, 2025

Choose a reason for hiding this comment

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

Where exactly one is getting reference to a private constructor? Shouldn't it be

cons_fn = Public_Type.cons
c = Meta.meta cons_fn : Meta.Constructor
c.fields . should_equal []
c.declaring_type . should_fail_with Private_Check
c.name . should_fail...

? But yeah, maybe that's happening behind the scene anyway.

@Akirathan Akirathan removed the CI: No changelog needed Do not require a changelog entry for this PR. label Jul 16, 2025
…e scope.

And not from the scope of the current node.
Calling private constructor is possible, there is no more private access check at invocation.
… from Java if reference was obtained from public method.
@Akirathan Akirathan merged commit ca8c480 into develop Jul 21, 2025
80 checks passed
@Akirathan Akirathan deleted the wip/akirathan/13078-private-generated-getters branch July 21, 2025 16:53
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.

.name syntax doesn't work across libraries due to (incorrect) encapsulation
4 participants