[generator] Ensure we don't generate unexpected NRT types, like 'void?'. #856
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: #850
When a user binds a library that contains an interface that implements another interface, we pull in all invokable members from both interfaces to create the
Invoker
type for the user's interface. If the base interface is a referenced assembly, the information we are working from has been read in via Cecil. Due to a bug caused by the combination of Cecil-read info and NRT generation, we will interpret the return types on the imported methods as alwaysnullable
, even for types likevoid
, which results in the uncompilablevoid?
.Example from
AndroidX.Core.Core
:This generates the
ISupportMenuInvoker
type:Which cause these following CSC errors:
The culprit is twofold:
CecilApiImporter
, we set theMethod.ManagedReturn
toSystem.Void
instead ofvoid
.CodeGenerationOptions
, we only check forvoid
to omit the null operator, notSystem.Void
.Note this also happens for all primitive types like
System.Int32
/int
.This commit fixes both aspects:
Method.ManagedReturn
to contain primitive types instead of fully qualified types.GetNullable
to correctly handle fully qualified types if one slips through.With this change, all of AndroidX/GPS/FB/MLKit can be successfully compiled with
<Nullable>enable</Nullable>
.