]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
WIP
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 17 May 2023 20:34:43 +0000 (22:34 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 30 Jan 2024 14:19:43 +0000 (15:19 +0100)
tests/Makefile.am
tests/generics/multiple-classes-constraints.test
vala/valadelegate.vala
vala/valagenericsymbol.vala
vala/valamethod.vala
vala/valaobjecttypesymbol.vala
vala/valastruct.vala
vala/valatypeparameter.vala

index a01040eae966078e3fc65b732c29ff040cbeffbf..2e6c1f7f0fb740959835ec8c71441a83b57d4f8a 100644 (file)
@@ -841,6 +841,7 @@ TESTS = \
        generics/method-to-delegate-incompatible.test \
        generics/method-to-delegate-incompatible-2.test \
        generics/method-to-delegate-incompatible-3.test \
+       generics/multiple-classes-constraints.test \
        generics/null-type.vala \
        generics/property-gobject-set.vala \
        generics/property-int-cast.vala \
index 4ca319f417bca0efdf5f65c30312d8c722e8861a..e1113cd1d8514c65781a855ad41398535f4410a8 100644 (file)
@@ -1,9 +1,13 @@
 Invalid Code
 
-class Foo {}
-class Fuu {}
+class Foo {
+}
+
+class Faz {
+}
 
-class Bar<G> where G : Foo, Fuu {
+class Bar<G> where G : Foo, Faz {
 }
 
-void main () {}
\ No newline at end of file
+void main () {
+}
index e7ec720a25aab4c87b3cc5bff42d1803f4385c72..348ce56309ba2c66f2b1b3f4a94f60e7d0102f09 100644 (file)
@@ -315,7 +315,9 @@ public class Vala.Delegate : TypeSymbol, Callable, GenericSymbol {
                }
 
                foreach (TypeParameter p in type_parameters) {
-                       p.check (context);
+                       if (!p.check (context)) {
+                               error = true;
+                       }
                }
 
                return_type.check (context);
index 8037afaa553d773e7cf2592e3307def8da6c7b36..54de021453e41275d0b249caa91b0e1c0d1d01ff 100644 (file)
@@ -53,14 +53,4 @@ public interface Vala.GenericSymbol : Symbol {
         * @return index of a type parameter, or -1
         */
        public abstract int get_type_parameter_index (string name);
-
-       public bool check_constraints () {
-               bool error = false;
-               foreach (var parameter in this.get_type_parameters ()) {
-                       if (!parameter.check_constraint ()) {
-                               error = true;
-                       }
-               }
-               return !error;
-       }
 }
index 6a1d686cf33b2bfc4ec959d1093706f86ec38e55..6122e45fe21c359b6b76be8db74c2772f42ae99b 100644 (file)
@@ -901,6 +901,12 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
                        return TraverseStatus.CONTINUE;
                });
 
+               foreach (TypeParameter p in type_parameters) {
+                       if (!p.check (context)) {
+                               error = true;
+                       }
+               }
+
                return_type.accept (traverse);
 
                var optional_param = false;
index 62547ef3b8aa9f955b4d5e79fef0a022d864cdbc..11735cf11bf4ae9f61b22ae4cd6a7d605a5a6fa7 100644 (file)
@@ -381,15 +381,17 @@ public abstract class Vala.ObjectTypeSymbol : TypeSymbol, GenericSymbol {
                        return !error;
                }
 
-               if (!this.check_constraints ()) {
-                       error = true;
-               }
-
                if (!external_package && has_attribute ("DBus") && !context.has_package ("gio-2.0")) {
                        error = true;
                        Report.error (source_reference, "gio-2.0 package required for DBus support");
                }
 
+               foreach (TypeParameter p in type_parameters) {
+                       if (!p.check (context)) {
+                               error = true;
+                       }
+               }
+
                return !error;
        }
 }
index 52c85dac725a71e000b5f7a3e48e1215f46b87c6..48092517765434223c14d05bf4c13de787d01081 100644 (file)
@@ -523,7 +523,9 @@ public class Vala.Struct : TypeSymbol, GenericSymbol {
                }
 
                foreach (TypeParameter p in type_parameters) {
-                       p.check (context);
+                       if (!p.check (context)) {
+                               error = true;
+                       }
                }
 
                foreach (Field f in fields) {
index 4314711b88bf9327c47bc968268aa2b992e6a586..4754d35dda0177bd7ece906c5009d687bca18403 100644 (file)
@@ -141,17 +141,25 @@ public class Vala.TypeParameter : TypeSymbol {
                return name == param2.name && parent_symbol == param2.parent_symbol;
        }
 
-       public bool check_constraint () {
+       public override bool check (CodeContext context) {
+               if (checked) {
+                       return !error;
+               }
+
+               checked = true;
+
                bool class_constraint = false;
                foreach (var type in get_type_constraints ()) {
                        if (type.symbol is Class) {
                                if (class_constraint) {
-                                       Report.error (source_reference, "a type parameter can only be constrained with one class type");
-                                       return false;
+                                       Report.error (source_reference, "a type parameter may only be constrained by a single class type");
+                                       error = true;
+                                       break;
                                }
                                class_constraint = true;
                        }
                }
-               return true;
+
+               return !error;
        }
 }