This is an archive of the discontinued LLVM Phabricator instance.

[SemaObjC] Properly diagnose type arguments and protocols mix in parameterized classes
ClosedPublic

Authored by bruno on Apr 11 2016, 5:09 PM.

Details

Summary

Under certain conditions clang currently fails to properly diagnostic ObjectC
parameter list when type args and protocols are mixed in the same list. This
happens when the first item in the parameter list is a (1) protocol, (2)
unknown type or (3) a list of protocols/unknown types up to the first type
argument. Fix the problem to report the proper error, example:

NSArray<M, NSValue *, NSURL, NSArray <id <M>>> *foo = @[@"a"];
NSNumber *bar = foo[0];
NSLog(@"%@", bar);

$ clang ...
x.m:7:13: error: angle brackets contain both a type ('NSValue') and a protocol ('M')

NSArray<M, NSValue *, NSURL, NSArray <id <M>>> *foo = @[@"a"];
        ~  ^

Diff Detail

Event Timeline

bruno updated this revision to Diff 53339.Apr 11 2016, 5:09 PM
bruno retitled this revision from to [SemaObjC] Properly diagnose type arguments and protocols mix in parameterized classes.
bruno updated this object.
bruno added a reviewer: doug.gregor.
bruno added subscribers: manmanren, dexonsmith, cfe-commits.
manmanren added inline comments.Apr 12 2016, 11:37 AM
lib/Parse/ParseObjc.cpp
1696–1699

I am a little confused about the original comment. Have we syntactically matched a type argument? All we have done is trying to parse the single identifiers, right?

1722

Should we set foundValidTypeId here too?

1728–1731

Should we emit diagnostics for all cases we set invalid to true?

1735

Please add comments here: not a type argument, not a protocol, treat it as unknown type.

1738

Is it necessary to have a "continue" here? Can we restructure this to get rid of the "continue"?

Hi Manman,

lib/Parse/ParseObjc.cpp
1696–1699

Yes, you're right! Going to update the entire comment to be more accurate

1722

See the comment below

1728–1731

The initial version of the patch was doing this. However, I could not come up with a testcase to exercise it, so I left it out. Gonna try harder!

1735

Ok

1738

Did this to remove some level of nested "if"s which I personally dislike, but can easily change that

bruno updated this revision to Diff 53470.Apr 12 2016, 2:56 PM

New patch after Manman's review.

manmanren accepted this revision.Apr 13 2016, 2:02 PM
manmanren edited edge metadata.
This revision is now accepted and ready to land.Apr 13 2016, 2:02 PM
bruno closed this revision.Apr 13 2016, 2:06 PM

Committed r266245