From d9fd205a53b9bec1d23912e91b5e4217a631dc66 Mon Sep 17 00:00:00 2001 From: Fernando Dodino Date: Fri, 15 Nov 2024 19:09:54 -0300 Subject: [PATCH 1/3] Fix #304 --- src/helpers.ts | 5 ++++- test/interpreter.test.ts | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index be157ed7..17109597 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -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 + } + const currentMethod = superNode.ancestors.find(isValidMethod)! return methodModule.lookupMethod(currentMethod.name, superNode.args.length, { lookupStartFQN: currentMethod.parent.fullyQualifiedName }) } diff --git a/test/interpreter.test.ts b/test/interpreter.test.ts index a514b68c..1f82c996 100644 --- a/test/interpreter.test.ts +++ b/test/interpreter.test.ts @@ -541,7 +541,6 @@ describe('Wollok Interpreter', () => { expect(errored).to.be.false }) - }) describe('DirectedInterpreter', () => { From 1872a8203664cd2953be0f7d957b02a393908fd2 Mon Sep 17 00:00:00 2001 From: Fernando Dodino Date: Mon, 18 Nov 2024 01:14:43 -0300 Subject: [PATCH 2/3] add paranoid extra validation for closures --- src/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 17109597..702701da 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -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' @@ -443,7 +443,7 @@ export const getNodeDefinition = (environment: Environment) => (node: Node): Nod export const superMethodDefinition = (superNode: Super, methodModule: Module): Method | undefined => { function isValidMethod(node: Node): node is Method { - return node.is(Method) && node.name !== CLOSURE_EVALUATE_METHOD + return node.is(Method) && node.name !== CLOSURE_EVALUATE_METHOD && node.parent.fullyQualifiedName !== CLOSURE_MODULE } const currentMethod = superNode.ancestors.find(isValidMethod)! return methodModule.lookupMethod(currentMethod.name, superNode.args.length, { lookupStartFQN: currentMethod.parent.fullyQualifiedName }) From 1eefd59c2faea2a8014ec7eb989639b51eb1472e Mon Sep 17 00:00:00 2001 From: palumbon Date: Tue, 19 Nov 2024 23:54:04 +0100 Subject: [PATCH 3/3] Hi isApplyMethodForClosures --- src/helpers.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 702701da..a185e4b6 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -217,7 +217,7 @@ export const usesField = (node: Node, field: Field): boolean => match(node)( when(Singleton)(node => { if (!node.isClosure()) return false - const applyMethod = node.methods.find(method => method.name === CLOSURE_EVALUATE_METHOD) + const applyMethod = node.methods.find(isApplyMethodForClosures) return !!applyMethod && usesField(applyMethod, field) }), when(Variable)(node => usesField(node.value, field)), @@ -441,9 +441,12 @@ export const getNodeDefinition = (environment: Environment) => (node: Node): Nod } } +export const isApplyMethodForClosures = (method: Method): boolean => + method.name === CLOSURE_EVALUATE_METHOD && method.parent.fullyQualifiedName.startsWith(`${CLOSURE_MODULE}#`) // TODO: Maybe re-define isClosure() ? + export const superMethodDefinition = (superNode: Super, methodModule: Module): Method | undefined => { function isValidMethod(node: Node): node is Method { - return node.is(Method) && node.name !== CLOSURE_EVALUATE_METHOD && node.parent.fullyQualifiedName !== CLOSURE_MODULE + return node.is(Method) && !isApplyMethodForClosures(node) } const currentMethod = superNode.ancestors.find(isValidMethod)! return methodModule.lookupMethod(currentMethod.name, superNode.args.length, { lookupStartFQN: currentMethod.parent.fullyQualifiedName })