Skip to content

NRT annotations not read from Cecil imported assemblies #857

@jpobst

Description

@jpobst

Context: #856

Like #856, given an example where we are generating an Invoker for a user interface that implements an interface in a referenced assembly, and NRT is turned on:

// In AndroidX.SavedState.SavedState
public interface AndroidX.SavedState.ISavedStateRegistryOwner: AndroidX.Lifecycle.ILifecycleOwner { ... }

// In Xamarin.AndroidX.Lifecycle.Common.dll
public interface ILifecycleOwner : IJavaObject, IDisposable, IJavaPeerable {
  Lifecycle Lifecycle { get; }
}

This generates the IFooBarInvoker type:

internal partial class ISavedStateRegistryOwnerInvoker: global::Java.Lang.Object, ISavedStateRegistryOwner{
  public Lifecycle? Lifecycle { get { .. } }
}

Which results in the CSC warning:

warning CS8766: Nullability of reference types in return type of 'Lifecycle? ISavedStateRegistryOwnerInvoker.Lifecycle.get' doesn't match implicitly implemented member 'Lifecycle ILifecycleOwner.Lifecycle.get' (possibly because of nullability attributes).

This is because we do not read in the [NullableAttribute] values when importing a referenced assembly. Thus we never treat anything as "not-null", and when we copy the method to the invoker we don't know that the return type is "not-null".

We need to update CecilApiImporter to interpret the NRT info encoded in the assembly, so we can generate matching methods. Unfortunately this is a very "not-trivial" process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugComponent does not function as intendedgeneratorIssues binding a Java library (generator, class-parse, etc.)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions