Slightly changed by Luca Bruno.
Fixes bug 626783
methods/bug613483.vala \
methods/bug620673.vala \
methods/bug622570.vala \
+ methods/bug626783.vala \
methods/bug639054.vala \
methods/bug642885.vala \
methods/bug642899.vala \
--- /dev/null
+public class Test<G,H> {
+}
+
+public void foo<T> (Test<T,int> t) {
+}
+
+public void bar<A,B> (Test<Test<A,B>,int> t) {
+}
+
+public T* baz<T> () {
+ return null;
+}
+
+void main () {
+ var f = new Test<int,int> ();
+ foo (f);
+
+ var g = new Test<Test<char,uint>,int> ();
+ bar (g);
+
+ int* i = baz ();
+}
return result;
}
+ public override DataType? infer_type_argument (TypeParameter type_param, DataType value_type) {
+ var array_type = value_type as ArrayType;
+ if (array_type != null) {
+ return element_type.infer_type_argument (type_param, array_type.element_type);
+ }
+
+ return null;
+ }
+
public override bool is_disposable () {
if (fixed_length) {
return element_type.is_disposable ();
return result;
}
+ /**
+ * Search for the type parameter in this formal type and match it in
+ * value_type.
+ */
+ public virtual DataType? infer_type_argument (TypeParameter type_param, DataType value_type) {
+ var value_type_arg_it = value_type.get_type_arguments ().iterator ();
+ foreach (var formal_type_arg in this.get_type_arguments ()) {
+ if (value_type_arg_it.next ()) {
+ var inferred_type = formal_type_arg.infer_type_argument (type_param, value_type_arg_it.get ());
+ if (inferred_type != null) {
+ return inferred_type;
+ }
+ }
+ }
+
+ return null;
+ }
+
public bool is_weak () {
if (this.value_owned) {
return false;
return result;
}
+ public override DataType? infer_type_argument (TypeParameter type_param, DataType value_type) {
+ if (type_parameter == type_param) {
+ var ret = value_type.copy ();
+ ret.value_owned = true;
+ return ret;
+ }
+
+ return null;
+ }
+
public override string to_qualified_string (Scope? scope = null) {
return type_parameter.name;
}
if (arg_it.next ()) {
Expression arg = arg_it.get ();
- var generic_type = param.variable_type as GenericType;
- if (generic_type != null && generic_type.type_parameter == type_param) {
- type_arg = arg.value_type.copy ();
- type_arg.value_owned = true;
+ type_arg = param.variable_type.infer_type_argument (type_param, arg.value_type);
+ if (type_arg != null) {
break;
}
// infer type arguments from expected return type
if (type_arg == null && target_type != null) {
- var generic_type = m.return_type as GenericType;
- if (generic_type != null && generic_type.type_parameter == type_param) {
- type_arg = target_type.copy ();
- type_arg.value_owned = true;
- }
+ type_arg = m.return_type.infer_type_argument (type_param, target_type);
}
if (type_arg == null) {
return result;
}
+ public override DataType? infer_type_argument (TypeParameter type_param, DataType value_type) {
+ var pointer_type = value_type as PointerType;
+ if (pointer_type != null) {
+ return base_type.infer_type_argument (type_param, pointer_type.base_type);
+ }
+
+ return null;
+ }
+
public override bool check (CodeContext context) {
error = !base_type.check (context);
return !error;