Эх сурвалжийг харах

Lfun: type checker checks for doubly defined function

Peter Thiemann 3 жил өмнө
parent
commit
7758658868
1 өөрчлөгдсөн 8 нэмэгдсэн , 5 устгасан
  1. 8 5
      book.tex

+ 8 - 5
book.tex

@@ -13385,7 +13385,7 @@ class TypeCheckLfun(TypeCheckLtup):
                 check_type_equal(param_t, arg_t, e)
             return return_t
           case _:
-            raise Exception('type_check_exp: in call, unexpected ' + \
+            raise Exception('type_check_exp: in call, unexpected ' +
                               repr(func_t))
       case _:
         return super().type_check_exp(e, env)
@@ -13411,10 +13411,13 @@ class TypeCheckLfun(TypeCheckLtup):
       case Module(body):
         env = {}
         for s in body:
-            match s:
-              case FunctionDef(name, params, bod, dl, returns, comment):
-                params_t = [t for (x,t) in params]
-                env[name] = FunctionType(params_t, returns)
+          match s:
+            case FunctionDef(name, params, bod, dl, returns, comment):
+              if name in env:
+                raise Exception('type_check: function ' +
+                                  repr(name) + ' defined twice')
+              params_t = [t for (x,t) in params]
+              env[name] = FunctionType(params_t, returns)
         self.type_check_stmts(body, env)
       case _:
         raise Exception('type_check: unexpected ' + repr(p))