Skip to content

Code with two GENERICSABLE classes doesn't compile #4

Description

@shinderuk

Here is an example with two GENERICSABLE classes: Foo and Qux.

#import "Foo.h"
#import "Qux.h"
#import <Foundation/Foundation.h>

int main(void)
{
    @autoreleasepool {
        NSArray<Foo> *fooArray = [NSArray array];
        NSString *bar = [fooArray lastObject].bar;

        NSArray<Qux> *quxArray = [NSArray array];
        NSArray<Foo> *array = [NSArray arrayWithArray:quxArray];
    }
}

Well, it doesn't compile

$ clang -Wall -Wextra -c -fobjc-arc main.m
main.m:8:23: warning: incompatible pointer types initializing 'NSArray<Foo> *__strong' with an expression of type 'NSArray<Qux> *' [-Wincompatible-pointer-types]
        NSArray<Foo> *fooArray = [NSArray array];
                      ^          ~~~~~~~~~~~~~~~
main.m:9:47: error: property 'bar' not found on object of type 'Qux *'
        NSString *bar = [fooArray lastObject].bar;
                                              ^
main.m:12:23: warning: incompatible pointer types initializing 'NSArray<Foo> *__strong' with an expression of type 'NSArray<Qux> *' [-Wincompatible-pointer-types]
        NSArray<Foo> *array = [NSArray arrayWithArray:quxArray];
                      ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings and 1 error generated.

It seems that the last imported GENERICSABLE class wins.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions