I try to replicate a method behaviour in an entity like language. Therefor i have a subtyping relation. The subtyping works fine, but it does not check the arrity.

   define reflexive, transitive <sub:
type rules 
  Class(c1, ClassExtend(c2), _, _, _) :-
  where store ClassType(c1) <sub: ClassType(c2)
  MethodCall(e, m, es) : t
    where definition of m : (t1*, t)
    and es : t2*
    and t2* <sub: t1* else error $[argument types -[t2*]- not a sub-type of method parameter types [t1*]] on es

The behaviour:

class A {
	A m(B a) { 
		return new B();

class B extends A {}
class C{}

new A().m(new B()) //works
new A().m(new A()) //error - like expected
new A().m(new C()) //error - like expected

new A().m(new B(), new A()) // no error
new A().m() // no error

I talked to Daco Harkes, who told me you’re busy with a new version, so i just put this here for completeness ;-)

Submitted on 28 April 2016 at 13:35

Log in to post comments