Skip to content

[generator] SmartEnum generator spits invalid code when using constants from Apple's framework libraries #5228

@dalexsoto

Description

@dalexsoto

Steps to Reproduce

  1. Create a binding project that has an SmartEnum using a system framework constant inside ApiDefinition
namespace SmartEnumsIssue {
	enum MyCustomActivityType {
		[DefaultEnumValue]
		[Field (null)]
		Null,

		[Field ("PostToFoo", "__Internal")]
		PostToFoo,

		[Field ("UIActivityTypePostToTwitter", Constants.UIKitLibrary)]
		PostToTwitter,

		[Field ("UIActivityTypePostToFacebook", Constants.UIKitLibrary)]
		PostToFacebook,
	}
}
  1. Make sure the project has Process enums as bindings instead of external types checked in project settings.
  2. Build project.

Expected Behavior

Generator does not create invalid code.

Actual Behavior

Generator creates invalid code:

Good:

[Field ("PostToFoo", "__Internal")]
internal unsafe static IntPtr PostToFoo {
	get {
		fixed (IntPtr *storage = &values [0])
			return Dlfcn.CachePointer (Libraries.__Internal.Handle, "PostToFoo", storage);
	}
}

Bad:

[Field ("UIActivityTypePostToTwitter", "/System/Library/Frameworks/UIKit.framework/UIKit")]
internal unsafe static IntPtr UIActivityTypePostToTwitter {
	get {
		fixed (IntPtr *storage = &values [1])
			return Dlfcn.CachePointer (Libraries./System/Library/Frameworks/UIKit.framework/UIKit.Handle, "UIActivityTypePostToTwitter", storage);
			// Invalid                        ^^^^^
	}
}

Environment

Using X.I master hash @ b1feb2f

Visual Studio Enterprise 2019 Preview for Mac
Version 8.0 Preview (8.0 build 865)
Installation UUID: f71bbeb3-b6a2-4163-8675-e7b7357bef0f
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 5.0.0.0 ( / b40230c0)

	Package version: 516000223

Mono Framework MDK
Runtime:
	Mono 5.16.0.223 (2018-06/7aadce3fad0) (64-bit)
	Package version: 516000223

NuGet
Version: 4.7.0.5148

.NET Core
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.1.6
	2.1.2
SDK: /usr/local/share/dotnet/sdk/2.1.500/Sdks
SDK Versions:
	2.1.500
	2.1.302
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

Xamarin.Profiler
Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 8

Apple Developer Tools
Xcode 10.1 (14460.46)
Build 10B61

Xamarin.Mac
Version: 5.5.1.174 (Visual Studio Enterprise)
Hash: b1feb2fd
Branch: master
Build date: 2018-12-04 23:23:12-0500

Xamarin.iOS
Version: 12.5.1.174 (Visual Studio Enterprise)
Hash: b1feb2fd
Branch: master
Build date: 2018-12-04 23:23:12-0500

Xamarin.Android
Version: 9.1.0.38 (Visual Studio Enterprise)
Android SDK: /Users/alex/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)
		7.1    (API level 25)
		8.0    (API level 26)
		8.1    (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 28.0.0

Microsoft Mobile OpenJDK
Java SDK: /Users/alex/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
1.8.0-9
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android Device Manager
Version: 1.2.0.1
Hash: 99d7ff4
Branch: remotes/origin/d16-0-p2~1
Build date: 2018-11-29 22:14:50 UTC

Xamarin Inspector
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

Xamarin Designer
Version: 4.17.1.189
Hash: 0e3953bd9
Branch: remotes/origin/d16-0-p1
Build date: 2018-11-07 13:21:06 UTC

Build Information
Release ID: 800000865
Git revision: c886aa47375d543b23a99ca64ee00253f9068ba7
Build date: 2018-11-29 22:18:40+00
Build branch: release-8.0
Xamarin extensions: 025104f5246ecbc274d8c400341f92294a32be5b

Operating System
Mac OS X 10.14.1
Darwin 18.2.0 Darwin Kernel Version 18.2.0
    Fri Oct  5 19:41:49 PDT 2018
    root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64

Example Project

SmartEnumsIssue.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIf an issue is a bug or a pull request a bug fixgeneratorIssues affecting the generatoriOSIssues affecting iOS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions