Treat the property type as boolean based on the r-value

Description

Customer's comment:

should be:

One improvement here is to detect the type of property based on the r-value (even if the declared type of `forStatusBarEdit` is unknown).
In this example, we are clearly assigning a boolean, thus the `is` prefix should be used.

Also, if the property declaration already has the `is` prefix, its type should be treated as boolean by default.

Environment

None

Activity

Show:
Alex Petuschak
October 23, 2018, 1:03 PM
Edited

Customer's comment (Jussi Paivinen<jussi.paivinen@houston-inc.com>):

The converter did not catch all "hidden" -> "isHidden" renames on UIViews
<...>
For a sample here, we had a prepareForReuse() function that the result looked like this

My reply:

If the declaration of `imageView` is not included in the current translation (i.e. `imageView` variable is declared in another file with is translated separately), the converter does not "know" that `imageView` has a type `UIImageView` (which is derived from `UIView`) and has a `hidden` property (mapped to `isHidden` in Swift): http://swiftify.me/4b84ok

If you include the declaration of `imageView`, `imageView.hidden` correctly translates to `isHidden`:
http://swiftify.me/4b84ok/1

I have scheduled an improvement to consider that the type of the `hidden` property is boolean based on the r-value (`NO`) used in the assignment.

Alex Petuschak
October 24, 2018, 2:15 PM

Note: in a generic case, we should infer a variable or property type from the r-value in assignment, if it was previously unknown.

Assignee

Alex Petuschak

Reporter

Alex Petuschak

Labels

Git Branch Name

None

GitHub Issue

None

Components

Fix versions

Priority

Medium
Configure