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

Use only Type instances as keys for State #7585

Merged
merged 3 commits into from
Aug 16, 2023

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Aug 15, 2023

Pull Request Description

Fixes #7572 by requiring keys to be Type instances.

Checklist

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

  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.

@@ -158,23 +158,23 @@ optimize_fragments : Vector SQL_Fragment -> Vector SQL_Fragment
optimize_fragments fragments =
builder = Vector.new_builder
go elem =
last_part = State.get SQL_Fragment.Code_Part
last_part = State.get SQL_Fragment
Copy link
Member Author

Choose a reason for hiding this comment

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

Code_Part is an atom constructor - that's a singleton. We could allow atom constructors as keys, but then there is problem with argumentless constructors like Boolean.True - they are immediately converted to Atom during Enso execution and atoms in general aren't singletons.

Restricting keys to types is simpler.

@@ -12,7 +12,7 @@ from project.Errors.Common import Uninitialized_State

Arguments:
- key: The key to associate your local_state with in the environment.
It is recommended that types be used as keys.
Use types as keys.
Copy link
Member Author

Choose a reason for hiding this comment

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

The signature of run : Any -> Any -> Any -> Any remains unchanged, as we don't have any type for type Some_Type.

@JaroslavTulach JaroslavTulach merged commit aa0413e into develop Aug 16, 2023
27 checks passed
@JaroslavTulach JaroslavTulach deleted the wip/jtulach/StateTypes_7572 branch August 16, 2023 13:54
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.

State accepts only Type as key - explain in docs
3 participants