syntax: Systematic signature conformance checks
authorJean Privat <jean@pryen.org>
Tue, 24 Mar 2009 14:06:18 +0000 (10:06 -0400)
committerJean Privat <jean@pryen.org>
Wed, 10 Jun 2009 13:35:09 +0000 (09:35 -0400)
These tests will catch errors that are not yet specifically handeled by working on the syntax tree.

Signed-off-by: Jean Privat <jean@pryen.org>

src/metamodel/static_type.nit
src/syntax/mmbuilder.nit

index 6cf53b7..0516f4f 100644 (file)
@@ -110,6 +110,11 @@ class MMSignature
                                return false
                        end
                end
+
+               if closures.length != s.closures.length then return false
+               for i in [0..closures.length[ do
+                       if not s.closures[i] < closures[i] then return false
+               end
                return true
        end
 
@@ -256,6 +261,13 @@ class MMClosure
                        return self
                end
        end
+
+       meth <(c: MMClosure): Bool
+       do
+               if c.is_optional and not is_optional then return false
+               if not c.is_break and is_break then return false
+               return c.signature < signature
+       end
 end
 
 # Inheritance relation between two types
index b59eaa9..ccdd2a6 100644 (file)
@@ -861,8 +861,13 @@ redef class PPropdef
                                end
                                s = isig
                                prop.signature = s
+                               #print "s is null"
                        end
 
+                       var nberr = v.tc.error_count
+                       #print "Check {prop.local_class}::{prop}{s} vs {ip.local_class}::{ip}{isig}"
+                       #print "s={s.object_id} isig={isig.object_id} isigorig={i.signature.object_id}"
+
                        #print "orig signature:  {i.signature.recv} . {i.signature}"
                        #print "inh signature:   {isig.recv} . {isig}"
                        #print "redef signature: {s.recv} . {s}"
@@ -885,6 +890,9 @@ redef class PPropdef
                                v.error(self, "Redef error: The function {prop.local_class}::{prop} redefines the procedure {ip.local_class}::{ip}.")
                        else if srt != null and isrt != null and not srt < isrt then
                                v.error(self, "Redef error: Expected {isrt} (as in {ip.local_class}::{ip}), got {srt} in {prop.local_class}::{prop}.")
+                       else if not s < isig and nberr == v.tc.error_count then
+                               # Systematic fallback for conformance check
+                               v.error(self, "Redef error: Incompatible redefinition of {ip.local_class}::{ip} with {prop.local_class}::{prop}")
                        else if srt != null and isrt != null and srt != isrt and prop isa MMAttribute then
                                # FIXME: To remove
                                v.warning(self, "Redef warning: Expected {isrt} (as in {ip.local_class}::{ip}), got {srt} in {prop.local_class}::{prop}.")