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

Second attempt at closing loophole #30

Merged
merged 3 commits into from Mar 24, 2024
Merged

Conversation

quephird
Copy link
Owner

@quephird quephird commented Mar 24, 2024

To clarify, the loophole was that although the user could properly create instances of LoxList by using bracket notation for a list literal in the REPL, they could also explicitly create an instance of List. This would result in an object in a hybrid state, without an elements property and no way to modify it to behave like an actual list. In this PR, we introduced the instanceType property for LoxClass so that when instances of it are created via LoxClass.call(), we create a LoxList instance if the class' name is List, and LoxInstance instance otherwise. This is what closes the loophole. (It should be noted that the name gets set to List when the interpreter is first instantiated and processes the class declaration for List in the standard library.)

We also included the following changes:

  • Introduced makeList() in Interpreter to get rid of code duplication but also made it public so that it could be used in unit tests
  • Moved equality conformance to LoxValue, which is used only for unit testing, for clarity

@quephird quephird merged commit ffca432 into main Mar 24, 2024
@quephird quephird deleted the close_up_list_loophole2 branch March 24, 2024 20:14
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.

None yet

1 participant