nitc: remove a warning on casts on MMTypeFormal
[nit.git] / src / syntax / typing.nit
index 8f0c77e..c3ef59c 100644 (file)
@@ -289,6 +289,15 @@ redef class AExternInitPropdef
        end
 end
 
+redef class ASignature
+       redef fun after_typing(v)
+       do
+               if self.n_opar != null and self.n_params.is_empty then
+                       v.warning(self, "Warning: superfluous parentheses.")
+               end
+       end
+end
+
 redef class AParam
        redef fun after_typing(v)
        do
@@ -403,6 +412,15 @@ redef class AParExpr
        end
 end
 
+redef class AParExprs
+       redef fun after_typing(v)
+       do
+               if n_exprs.is_empty then
+                       v.warning(self, "Warning: superfluous parentheses.")
+               end
+       end
+end
+
 redef class AVardeclExpr
        var _variable: nullable VarVariable
        redef fun variable do return _variable.as(not null)
@@ -537,7 +555,7 @@ redef class AAbortExpr
 end
 
 # An abstract control structure with feature escapable block
-class AAbsControl
+abstract class AAbsControl
        super AExpr
        # The corresponding escapable block
        readable var _escapable: nullable EscapableBlock
@@ -1110,7 +1128,7 @@ end
 redef class AArrayExpr
        redef fun after_typing(v)
        do
-               var stype = v.check_conform_multiexpr(null, n_exprs)
+               var stype = v.check_conform_multiexpr(null, n_exprs.n_exprs)
                if stype != null then do_typing(v, stype)
        end
 
@@ -1168,7 +1186,7 @@ redef class ASuperExpr
                        assert p isa MMMethod
                        _init_in_superclass = p
                        register_super_init_call(v, p)
-                       if n_args.length > 0 then
+                       if n_args.n_exprs.length > 0 then
                                var signature = get_signature(v, v.self_var.stype.as(not null), p, true)
                                process_signature(v, signature, p.name, compute_raw_arguments)
                        end
@@ -1604,9 +1622,6 @@ redef class ASuperInitCall
                                if c == prev_class then
                                        prev_class = null
                                else if c == cla then
-                                       if prev_class != null then
-                                               v.error(self, "Error: Constructor of {c} must be invoked before constructor of {prev_class}")
-                                       end
                                        esic.add(property)
                                        break
                                end
@@ -1626,6 +1641,9 @@ redef class ANewExpr
                        v.error(self, "Error: try to instantiate abstract class {t.local_class}.")
                        return
                end
+               if t.is_nullable then
+                       v.error(self, "Type error: cannot instantiate the nullable type {t}.")
+               end
                var name: Symbol
                if n_id == null then
                        name = once "init".to_symbol
@@ -1840,7 +1858,7 @@ redef class ACallFormExpr
                                        n = new AClosureCallExpr.init_aclosurecallexpr(n_id, n_args, n_closure_defs)
                                        n._variable = variable
                                else
-                                       if not n_args.is_empty then
+                                       if not n_args.n_exprs.is_empty or n_args isa AParExprs then
                                                v.error(self, "Error: {name} is variable, not a function.")
                                                return
                                        end
@@ -2020,7 +2038,7 @@ redef class AClosureDef
        end
 end
 
-class ATypeCheckExpr
+abstract class ATypeCheckExpr
        super AExpr
        private fun check_expr_cast(v: TypingVisitor, n_expr: AExpr, n_type: AType)
        do
@@ -2031,7 +2049,10 @@ class ATypeCheckExpr
                if etype == ttype then
                        v.warning(self, "Warning: Expression is already a {ttype}.")
                else if etype < ttype then
-                       v.warning(self, "Warning: Expression is already a {ttype} since it is a {etype}.")
+                       if not ttype isa MMTypeFormal then
+                               # the old metamodel is not that great with formal types
+                               v.warning(self, "Warning: Expression is already a {ttype} since it is a {etype}.")
+                       end
                else if etype isa MMTypeNone then
                        # ttype is not nullable because of prevous test
                        v.warning(self, "Warning: Expression is null therefore cannot be a {ttype}.")
@@ -2123,3 +2144,15 @@ redef class AOnceExpr
        end
 end
 
+redef class ADebugTypeExpr
+       redef fun after_typing(v)
+       do
+               if not v.check_expr(n_expr) then return
+               if not n_type.is_typed then return
+               var etype = n_expr.stype
+               var ttype = n_type.stype
+               if etype != ttype then
+                       v.warning(self, "Warning: Expression is a {etype}, expected {ttype}.")
+               end
+       end
+end