Possible incorrect translation

Description

  • Input header code:

  • Source Code:
    NSMutableDictionary<NSNumber *, NSMutableDictionary<NSNumber *, NSNumber *> *> *lookupX =
    [NSMutableDictionary dictionary];

  • Conversion Result:
    var lookupX: [NSNumber : [NSNumber : NSNumber]?]? = [:]

  • Expected:
    var lookupX: [NSNumber : [NSNumber : NSNumber]]? = [:]

pls clarify which result is correct

Environment

None

Activity

Show:
Alex Petuschak
October 20, 2020, 11:42 AM

var lookupX: [NSNumber : [NSNumber : NSNumber]?]? = [:]

looks a bit better to me since it consistently converts pointers to optionals.

`NSMutableDictionary<NSNumber *, NSNumber *> *` is passed by reference in Objective-C, thus the resulting Swift type `[NSNumber : NSNumber]?` should rather be nullable.

However, this change may or may not require accompanying changes to the code using such variables, and also to TargetTypeVisitor. I can re-run project-based integration tests (available only on macOS) to see if your changes affect the error rate.

For the above reason, I’m asking to avoid massive changes in a single branch.

 

There are numerous cases when we omit optionals for pointer declarations - for example, NSNumber in your sample is kept non-optional by design (otherwise there will be too much overhead to unwrap all usages of NSNumber values in the Swift code).

Serhii Kuzmychov
October 20, 2020, 11:48 AM

this is the artifact I got after a fix type rules, specifically related to pointers, the piece of code that deal with it does not care about pointers at all, but! unit test contains cases which I consider as ‘source of truth' so I will fix unit test in scope of this taskas for 'cases when we omit optionals’ np, this can tweak on the way easily

Assignee

Serhii Kuzmychov

Reporter

Serhii Kuzmychov

Labels

None

Git Branch Name

None

GitHub Issue

None

Fix versions

Priority

Medium
Configure