Skip to content

Commit

Permalink
reproducing error
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Nov 10, 2024
1 parent 6ad63ac commit a95e3a9
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 2 deletions.
64 changes: 63 additions & 1 deletion test/interpreter.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, should, use } from 'chai'
import { restore } from 'sinon'
import sinonChai from 'sinon-chai'
import { EXCEPTION_MODULE, Evaluation, REPL, WRENatives } from '../src'
import { EXCEPTION_MODULE, Evaluation, REPL, WRENatives, buildEnvironment } from '../src'
import { DirectedInterpreter, interprete, Interpreter } from '../src/interpreter/interpreter'
import link from '../src/linker'
import { Body, Class, Field, Literal, Method, Package, ParameterizedType, Reference, Return, Send, Singleton, SourceIndex, SourceMap } from '../src/model'
Expand Down Expand Up @@ -256,6 +256,68 @@ describe('Wollok Interpreter', () => {
it('for closure', () => {
checkSuccessfulResult('{1 + 2}', '{1 + 2}')
})

it('should be able to execute sentences related to a hierarchy defined in different packages', () => {
const replEnvironment = buildEnvironment([{
name: 'jefeDeDepartamento.wlk', content: `
import medico.*
// con ésto falla
class Jefe inherits Medico {
// si comento la línea de arriba y utilizo ésto no falla
// class Jefe {
const subordinados = #{}
override method atenderA(unaPersona) {
subordinados.anyOne().atenderA(unaPersona)
}
}
`,
}, {
name: 'medico.wlk', content: `
import persona.*
class Medico inherits Persona {
const dosis
override method contraerEnfermedad(unaEnfermedad) {
super(unaEnfermedad)
self.atenderA(self)
}
method atenderA(unaPersona) {
unaPersona.recibirMedicamento(dosis)
}
}
`,
}, {
name: 'persona.wlk', content: `
class Persona {
const enfermedades = []
method contraerEnfermedad(unaEnfermedad) {
enfermedades.add(unaEnfermedad)
}
method saludar() = "hola"
}
`,
}, {
name: REPL, content: `
import medico.*
object testit {
method test() = new Medico(dosis = 200).saludar()
}
`,
}])
interpreter = new Interpreter(Evaluation.build(replEnvironment, WRENatives))
const { error } = interprete(interpreter, 'testit.test()')
console.info(error)
expect(error).to.be.undefined
})

})

})
Expand Down
61 changes: 60 additions & 1 deletion test/linker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, should, use } from 'chai'
import { GAME_MODULE, OBJECT_MODULE } from '../src'
import { getPotentiallyUninitializedLazy } from '../src/decorators'
import link, { canBeReferenced, linkSentenceInNode } from '../src/linker'
import { Body, Class, Closure, Describe, Environment, Field, Import, Method, Mixin, NamedArgument, Node, Package, Parameter, ParameterizedType, Reference, Return, Sentence, Singleton, Test, Variable } from '../src/model'
import { Body, Class, Closure, Describe, Environment, Field, Import, Method, Mixin, NamedArgument, Node, Package, Parameter, ParameterizedType, Reference, Return, Sentence, Singleton, Test, Variable, Literal } from '../src/model'
import * as parse from '../src/parser'
import { linkerAssertions } from './assertions'
import { environmentWithEntities, WREEnvironment } from './utils'
Expand Down Expand Up @@ -464,6 +464,65 @@ describe('Wollok linker', () => {
C.methods[0].sentences[0].should.target(C.fields[0])
})

it('should target references to members inherited from superclass in different packages', () => {
const environment = link([
new Package({
name: 'aaa',
imports: [
new Import({ isGeneric: true, entity: new Reference({ name: 'bbb' }) }),
],
members: [
new Class({
name: 'C',
supertypes: [new ParameterizedType({ reference: new Reference({ name: 'bbb.B' }) })],
members: [
new Method({
name: 'm2',
body: new Body({ sentences: [new Literal({ value: '2' })] }),
}),
],
}),
],
}),
new Package({
name: 'bbb',
imports: [
new Import({ isGeneric: true, entity: new Reference({ name: 'zzz' }) }),
],
members: [
new Class({
name: 'B',
supertypes: [new ParameterizedType({ reference: new Reference({ name: 'zzz.A' }) })],
members: [
new Method({
name: 'm',
body: new Body({ sentences: [new Reference({ name: 'x' })] }),
}),
],
}),
],
}),
new Package({
name: 'zzz',
members: [
new Class({
name: 'A', members: [
new Field({ name: 'x', isConstant: false }),
],
}),
],
}),
], WREEnvironment)

const C = environment.getNodeByFQN<Class>('aaa.C')
const B = environment.getNodeByFQN<Class>('bbb.B')
const A = environment.getNodeByFQN<Class>('zzz.A')

C.supertypes[0].reference.should.target(B)
B.supertypes[0].reference.should.target(A)
B.methods[0].sentences[0].should.target(A.fields[0])
})

it('should target references overriden on mixins to members inherited from superclass', () => {
const environment = link([
new Package({
Expand Down

0 comments on commit a95e3a9

Please sign in to comment.