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

Fix #304 Super inside closure #310

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BOOLEAN_MODULE, CLOSURE_EVALUATE_METHOD, CLOSURE_TO_STRING_METHOD, INITIALIZE_METHOD, KEYWORDS, NUMBER_MODULE, OBJECT_MODULE, STRING_MODULE, VOID_WKO, WOLLOK_BASE_PACKAGE } from './constants'
import { BOOLEAN_MODULE, CLOSURE_EVALUATE_METHOD, CLOSURE_MODULE, CLOSURE_TO_STRING_METHOD, INITIALIZE_METHOD, KEYWORDS, NUMBER_MODULE, OBJECT_MODULE, STRING_MODULE, VOID_WKO, WOLLOK_BASE_PACKAGE } from './constants'
import { getPotentiallyUninitializedLazy } from './decorators'
import { count, is, isEmpty, last, List, match, notEmpty, otherwise, valueAsListOrEmpty, when, excludeNullish } from './extensions'
import { RuntimeObject, RuntimeValue } from './interpreter/runtimeModel'
Expand Down Expand Up @@ -442,7 +442,10 @@ export const getNodeDefinition = (environment: Environment) => (node: Node): Nod
}

export const superMethodDefinition = (superNode: Super, methodModule: Module): Method | undefined => {
const currentMethod = superNode.ancestors.find(is(Method))!
function isValidMethod(node: Node): node is Method {
return node.is(Method) && node.name !== CLOSURE_EVALUATE_METHOD && node.parent.fullyQualifiedName !== CLOSURE_MODULE
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Acá por qué node.parent.fullyQualifiedName !== CLOSURE_MODULE? Esto evita que se pueda usar super() dentro de la clase Closure (que por ahora no pasa).

Copy link
Contributor

@PalumboN PalumboN Nov 19, 2024

Choose a reason for hiding this comment

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

Ahí leí el comentario de @ivojawer (que se había solucionado) y estoy de acuerdo! Pero la condición había quedado mal escrita (maldito De Morgan).

Ahí delegué en una función isApplyMethodForClosures para que no haya confusión (de hecho, ya la reutilicé en otro lado).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Groso @PalumboN !! Tire magia!!!

const currentMethod = superNode.ancestors.find(isValidMethod)!
return methodModule.lookupMethod(currentMethod.name, superNode.args.length, { lookupStartFQN: currentMethod.parent.fullyQualifiedName })
}

Expand Down
1 change: 0 additions & 1 deletion test/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ describe('Wollok Interpreter', () => {
expect(errored).to.be.false
})


})

describe('DirectedInterpreter', () => {
Expand Down
Loading