Page 1 of 1

Constructor's type not determined

Posted: 8 Aug 2014 15:21
by Martin Meyer
Hi Thomas,

the compiler build 7500 throws error c520 : Impossible to determine the type of the term on this code. I suppose, it is not intended:

Code: Select all

interface myObj{@Type}     domains         useTheParameter = @Type. end interface myObj   class myObj{@Type} : myObj{@Type} end class myObj   implement myObj{@Type} end implement myObj   implement main     clauses         run() :-             _ = myObj{integer}::new. end implement main
Regards,
Martin

Posted: 8 Aug 2014 16:03
by Vitaly Markov
parenthesis:

run() :-
_ = myObj{integer}::new().

Posted: 8 Aug 2014 17:24
by Martin Meyer
Hello Markov,

appending the parenthesis is not compellent. myObj{integer}::new is a legal expression. It has the type () -> myObj{integer}, i.e. a function type.

Regards,
Martin

Posted: 9 Aug 2014 5:43
by Vitaly Markov
Hello Meyer!
You try:

run() :-
_ = myObj{integer}::new().

It is a good tablet :-)

Posted: 9 Aug 2014 11:27
by Thomas Linder Puls
The type checker is only supposed to say "impossible to determine the type" if something remains polymorphic, i.e. if one of the types can be chosen arbitrarily and still solve the system.

That would have been the case it you had written:

Code: Select all

clauses     run() :-         _ = myObj::new.
But when instantiating the class with integer, only integer will solve the system. So this is a bug.

The situation will however not happen often, because normally you will use the value (rather than just throwing it away like here), and then the usage will typically fix the type:

Code: Select all

clauses     run() :-        Factory = myObj::new,        use(Factory).
Should nothing fix the type, you can fix it explicitly using hasDomain:

Code: Select all

clauses     run() :-        hasDomain(core::function{integer}, Factory),        Factory = myObj::new,        use(Factory).
Or using the new (i.e. vip 7.5) function form of hasDomain:

Code: Select all

clauses     run() :-        Factory = hasDomain(core::function{integer}, myObj::new),        use(Factory).
We will of course address the bug.

Posted: 9 Aug 2014 12:02
by Martin Meyer
Thanx Thomas and VITALY (I guess, by "Hello Meyer" you are giving me a wink, that Vitaly is your first name :D )!

Best Regards,
Martin