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

Interpreter fails to find object member #647

Closed
peterwvj opened this issue Oct 10, 2017 · 4 comments
Closed

Interpreter fails to find object member #647

peterwvj opened this issue Oct 10, 2017 · 4 comments
Labels
bug Incorrect behaviour of the tool Mergable A fix is available on a branch to merge for release
Milestone

Comments

@peterwvj
Copy link
Member

If you execute Entry`Run(), as defined below, the interpreter wrongly reports that the operation member is missing. The problem is the same in VDMJ.

class A

operations

public op : nat ==> ()
op (-) == skip;

end A

class B

operations

public op : bool ==> ()
op (-) == skip;

end B

class Entry

operations

public static Run : () ==> nat
Run () ==
let
	c1 : nat | bool = 1,
	c2 : nat | bool = true,
	objs = [new A(), new B()]
in
(
	for i = 1 to 2 do
		objs(i).op(if i = 1 then c1 else c2);
		
	return 2;	
);

end Entry

Expected result is 2, but actually the following error is produced:

Error 4035: Object has no field: op in 'Entry' (...A.vdmpp) at line 32:11
@peterwvj peterwvj added the bug Incorrect behaviour of the tool label Oct 10, 2017
@peterwvj peterwvj added this to the v2.5.4 milestone Oct 10, 2017
peterwvj added a commit that referenced this issue Oct 10, 2017
This table should be enabled once issue #647 is fixed
@nickbattle
Copy link
Contributor

nickbattle commented Oct 10, 2017

Because the objs sequence is a mixture of class types, it is creating a simulated "union" class for the sequence that has the signatures of the unions of the common members. Unfortunately it seems to have got that process wrong in this case. The simulated class/op is *union_A_B'op(nat), rather than *union_A_B'op(nat | bool). So the lookup of the second bool operation call is failing to find the actual bool member of B. I'll look at the simulated class creation process...

@nickbattle
Copy link
Contributor

In fact the creation of the simulated union class is correct. But when the first operation call is made via objs(i), it assumes (wrongly) that it can use the current arg type as the type of the argument for all future invocations at this point in the spec. So the second invocation is looking for op(nat) again, which fails. I think the fix is simple.

@peterwvj
Copy link
Member Author

Cool, thanks for explaining!

@nickbattle nickbattle added the Mergable A fix is available on a branch to merge for release label Oct 10, 2017
@nickbattle
Copy link
Contributor

OK, now fixed in ncb/development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behaviour of the tool Mergable A fix is available on a branch to merge for release
Projects
None yet
Development

No branches or pull requests

2 participants