From e83b95641f911e44c8c092bc0eef7743df0cd73d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 7 Jul 2015 03:57:53 +0000 Subject: Substitute type arguments into uses of Objective-C interface members. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When messaging a method that was defined in an Objective-C class (or category or extension thereof) that has type parameters, substitute the type arguments for those type parameters. Similarly, substitute into property accesses, instance variables, and other references. This includes general infrastructure for substituting the type arguments associated with an ObjCObject(Pointer)Type into a type referenced within a particular context, handling all of the substitutions required to deal with (e.g.) inheritance involving parameterized classes. In cases where no type arguments are available (e.g., because we're messaging via some unspecialized type, id, etc.), we substitute in the type bounds for the type parameters instead. Example: @interface NSSet> : NSObject - (T)firstObject; @end void f(NSSet *stringSet, NSSet *anySet) { [stringSet firstObject]; // produces NSString* [anySet firstObject]; // produces id (the bound) } When substituting for the type parameters given an unspecialized context (i.e., no specific type arguments were given), substituting the type bounds unconditionally produces type signatures that are too strong compared to the pre-generics signatures. Instead, use the following rule: - In covariant positions, such as method return types, replace type parameters with “id” or “Class” (the latter only when the type parameter bound is “Class” or qualified class, e.g, “Class”) - In other positions (e.g., parameter types), replace type parameters with their type bounds. - When a specialized Objective-C object or object pointer type contains a type parameter in its type arguments (e.g., NSArray*, but not NSArray *), replace the entire object/object pointer type with its unspecialized version (e.g., NSArray *). llvm-svn: 241543 --- clang/test/PCH/objc_parameterized_classes.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'clang/test/PCH/objc_parameterized_classes.m') diff --git a/clang/test/PCH/objc_parameterized_classes.m b/clang/test/PCH/objc_parameterized_classes.m index f4fd0926be3..616d4a2659d 100644 --- a/clang/test/PCH/objc_parameterized_classes.m +++ b/clang/test/PCH/objc_parameterized_classes.m @@ -21,6 +21,7 @@ __attribute__((objc_root_class)) typedef PC1 PC1Specialization1; +typedef PC1Specialization1 PC1Specialization2; #else @interface PC1 PC1Specialization1; // expected-note@15{{type parameter 'U' declared here}} @end -typedef PC1Specialization1 PC1Specialization2; // expected-error{{type arguments cannot be applied to already-specialized class type 'PC1Specialization1' (aka 'PC1')}} +typedef PC1Specialization1 PC1Specialization3; // expected-error{{type arguments cannot be applied to already-specialized class type 'PC1Specialization1' (aka 'PC1')}} + +typedef PC1Specialization2 PC1Specialization4; // expected-error{{already-specialized class type 'PC1Specialization2' (aka 'PC1Specialization1')}} #endif -- cgit v1.2.3