Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* fixed: ObjCProtocol to NSObject promoter in case of private classes and multiple constructors #753

Conversation

dkimitsa
Copy link
Contributor

@dkimitsa dkimitsa commented Oct 8, 2023

Fix

it fixes following case

public class Test {
    public void test() {
        new Delegate();
    }

    private static class Delegate implements NSObjectProtocol {
        
    }
}

causes compilation warning:

ObjCProtocol to NSObject failed: too many public constructors

and runtime crash if this class is used as NSObjectProtocol with ObjC:

Delegate cannot be cast to org.robovm.objc.ObjCObject at org.robovm.objc.ObjCObject$Marshaler.protocolToNative

Promoter was working only in case one constructor is present.

But in case of private classes there is additional synthetic public constructor is created. Code updated to ignore synthetic constructors and allow multiple constructors to be available

Inspection

Added Intellij Idea ispections to highlight following cases:

  • if class implements NSObjectProtocol and extends java.lang.Object -- warning with quick fix to extend from NSObject (actually this class will be promoted)
  • if class extends some class that implements NSObjectProtocol and extends java.lang.Object -- warning for both classes and quick fix to navigate to supper that can be updated with NSObject super.
  • if class implements protocol but extends class that has some hierarchy behind -- mark as error as this class will not be handled by promoter and will cause Runtime crash
image

… and multiple constructors

## Promoter was working only in case one constructor is present.
But in case of private classes there is additional synthetic public constructor is created.
Code updated to ignore synthetic constructors and allow multiple constructors to be available

## Inspection
Added Intellij Idea ispections to highlight following cases:
- if class implements NSObjectProtocol and extends `java.lang.Object` -- warning with quick fix to extend from NSObject (actually this class will be promoted)
- if class extends some class that implements NSObjectProtocol and extends `java.lang.Object` -- warning for both classes and quick fix to navigate to supper that can be updated with NSObject super.
- if class implements protocol but extends class that has some hierarchy behind -- mark as error as this class will not be handled by promoter and will cause Runtime crash
@Tom-Ski Tom-Ski merged commit 6d8bfc9 into MobiVM:master Oct 8, 2023
1 check passed
dkimitsa added a commit to dkimitsa/robovm that referenced this pull request Apr 15, 2024
… and multiple constructors (MobiVM#753)

## Promoter was working only in case one constructor is present.
But in case of private classes there is additional synthetic public constructor is created.
Code updated to ignore synthetic constructors and allow multiple constructors to be available

## Inspection
Added Intellij Idea ispections to highlight following cases:
- if class implements NSObjectProtocol and extends `java.lang.Object` -- warning with quick fix to extend from NSObject (actually this class will be promoted)
- if class extends some class that implements NSObjectProtocol and extends `java.lang.Object` -- warning for both classes and quick fix to navigate to supper that can be updated with NSObject super.
- if class implements protocol but extends class that has some hierarchy behind -- mark as error as this class will not be handled by promoter and will cause Runtime crash

(cherry picked from commit 6d8bfc9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants