This is an archive of the discontinued LLVM Phabricator instance.

Get class property selectors from property decl if it exists
ClosedPublic

Authored by herzka on Feb 14 2017, 2:33 PM.

Details

Summary

Before this fix, trying to get or set a class property using dot syntax would always use the constructed name (x or setX:), which might not match the real selector if the getter or setter is specified via property attributes. Now, the selectors in the declaration have priority over the constructed names, which is consistent with instance properties.

Diff Detail

Event Timeline

herzka created this revision.Feb 14 2017, 2:33 PM
herzka planned changes to this revision.Feb 14 2017, 2:37 PM

This issue applies to getters too. I'll make this fix broader.

I think the real fix for both is to construct the ObjCPropertyRefExpr using the ObjCPropertyDecl so that it's considered an explicit property. Currently, it still gets considered implicit, which is not true. I don't know what implications changing that may have, though. This fix seems safer.

herzka updated this revision to Diff 88448.Feb 14 2017, 2:40 PM
herzka retitled this revision from Get class property setter selector from property decl if exists to Get class property selectors from property decl if it exists.
herzka edited the summary of this revision. (Show Details)
herzka updated this revision to Diff 88519.Feb 15 2017, 6:21 AM
herzka edited the summary of this revision. (Show Details)

Added full context. Sorry about that! This is my first contribution, and I don't know how I completely missed that line while going through the steps.

compnerd requested changes to this revision.Feb 15 2017, 3:06 PM

Please add a test for this.

lib/Sema/SemaExprObjC.cpp
1989

Use auto.

This revision now requires changes to proceed.Feb 15 2017, 3:06 PM
herzka updated this revision to Diff 88650.Feb 15 2017, 7:14 PM
herzka edited edge metadata.

Added test, used auto

herzka marked an inline comment as done.Feb 15 2017, 7:14 PM
herzka updated this revision to Diff 88652.Feb 15 2017, 7:59 PM

Rename selectors

I think Im misunderstanding something. How does the test actually test what you are changing?

herzka added a comment.EditedFeb 16 2017, 7:40 PM

Currently, A.customGetterProperty would be turned into [A customGetterProperty], which would fail to compile because that selector isn't declared anywhere. With my fix, it does compile because it (correctly) resolves to [A customGet], which does exist. Similarly, A.customSetterProperty = 1 got turned into [A setCustomSetterProperty:1] (another nonexistent selector), but now becomes [A customSet:1].

Here are the errors I get when I run the test without my fix:

error: 'error' diagnostics seen but not expected:
  File /Users/herzka/dev/OSS/llvm/tools/clang/test/SemaObjC/objc-class-property.m Line 45: no setter method 'setCustomSetterProperty:' for assignment to property
  File /Users/herzka/dev/OSS/llvm/tools/clang/test/SemaObjC/objc-class-property.m Line 46: no getter method for read from property
2 errors generated.
compnerd accepted this revision.Feb 17 2017, 9:00 AM

Ah, I had missed the -verify option on the test. Yes, that makes sense. Ternary may have flowed the conditional code better. Do you need someone to commit this on your behalf?

This revision is now accepted and ready to land.Feb 17 2017, 9:00 AM

@compnerd, yes please. I don't have commit access. Thanks for the review!

compnerd closed this revision.Feb 20 2017, 3:57 PM

SVN r295683