]> 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>
Sun, 21 Apr 2024 11:46:26 +0000 (13:46 +0200)
tests/Makefile.am
tests/generics/multiple-classes-constraints.test
vala/valagenericsymbol.vala
vala/valaobjecttypesymbol.vala
vala/valatypeparameter.vala

index a452b726ec1bc255bd62ba9d56774938cf8126b7..7d9751dd0804739102dc90d59627bdb7d85527b7 100644 (file)
@@ -844,6 +844,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 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 94dd53cc332293f83b46e2065884b583079239ec..0ba8c6d70155aabedaa03530551d0ce6d1f94344 100644 (file)
@@ -381,10 +381,6 @@ 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");
index bcf383b10a1716de63a6d8fc71915625153becbe..26d8f922f7c576e7d874c94f71a2481674371d45 100644 (file)
@@ -141,20 +141,6 @@ public class Vala.TypeParameter : TypeSymbol {
                return name == param2.name && parent_symbol == param2.parent_symbol;
        }
 
-       public bool check_constraint () {
-               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;
-                               }
-                               class_constraint = true;
-                       }
-               }
-               return true;
-       }
-
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;
@@ -168,6 +154,18 @@ public class Vala.TypeParameter : TypeSymbol {
                        return false;
                }
 
+               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 may only be constrained by a single class type");
+                                       error = true;
+                                       break;
+                               }
+                               class_constraint = true;
+                       }
+               }
+
                return !error;
        }
 }