morloc-project / morloc

A typed, polyglot, functional language
GNU General Public License v3.0
195 stars 4 forks source link

Cannot use a variable storing an unannotated primitive in a declared application #7

Closed arendsee closed 4 years ago

arendsee commented 4 years ago

The following code fails:

import cppbase (add)
export foo
y = 40;
foo x = add x y;

Here is there error message:

 :  --- realize ---
 : 0 foo :: Num -> Num
     _ :: {double@CppLang -> double@CppLang}
     LamS [x]
       1 :: Num
            _ :: {double@CppLang}
            AppS   3 add :: Num -> Num -> Num
                        _ :: {double@CppLang -> double@CppLang -> double@CppLang}
                        CallS add <CppLang>
                   4 x :: Num
                        _ :: {double@CppLang}
                        VarS x
                   5 y :: Num      <<<< should be: {double@CppLang}, not the general Num type
                        _ :: {}
                        NumS
 :  ---------------

OtherError: Expected GAST

The error is occurring in the makeGAST function called in the realize step of the generator algorithm. A GAST is a General Abstract Syntax Tree. The makeGAST function is called because the realize function failed to find a valid concrete realization for the function foo. The reason it could not is because y does not have a concrete type. The inference engine SHOULD have transferred the concrete type known from add's signature to y. This is a bug in the inference code (infer.hs).