generics/arrays-not-supported-3.test \
generics/class-property-override.vala \
generics/constraints.vala \
+ generics/constraints-incompatible.test \
generics/constructor-chain-up.vala \
generics/delegate-return-type-missing.test \
generics/floating-type-cast.vala \
--- /dev/null
+Invalid Code
+
+class Bar {
+}
+
+class SubBar : Bar {
+}
+
+interface IFoo<G> where G : SubBar {
+}
+
+class Foo<T> : IFoo<T> where T : Bar {
+}
+
+void main () {
+}
/* temporarily ignore type parameters */
if (target_type is GenericType) {
+ unowned DataType? constraint_type = ((GenericType) target_type).type_parameter.type_constraint;
+ if (constraint_type != null) {
+ return compatible (constraint_type);
+ }
return true;
}
return false;
}
+ var it = ((GenericSymbol) type_symbol).get_type_parameters ().iterator ();
foreach (DataType type in get_type_arguments ()) {
if (!type.check (context)) {
return false;
}
+
+ it.next ();
+ unowned DataType? constraint_type = it.get ().type_constraint;
+ if (constraint_type != null && !type.compatible (constraint_type)) {
+ error = true;
+ Report.error (type.source_reference, "Cannot convert from `%s' to `%s'", type.to_string (), constraint_type.to_string ());
+ return false;
+ }
}
return true;
return result;
}
+ public override bool compatible (DataType target_type) {
+ unowned DataType? constraint_type = type_parameter.type_constraint;
+ if (constraint_type != null) {
+ return constraint_type.compatible (target_type);
+ }
+
+ return base.compatible (target_type);
+ }
+
public override DataType get_actual_type (DataType? derived_instance_type, List<DataType>? method_type_arguments, CodeNode? node_reference) {
var result = this.copy ();