Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Trivial Enums not marshaling correctly in protocols #329

Open
stephen-hawley opened this issue Mar 12, 2020 · 0 comments
Open

Trivial Enums not marshaling correctly in protocols #329

stephen-hawley opened this issue Mar 12, 2020 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@stephen-hawley
Copy link
Contributor

Here's a test:

		[Test]
		public void MakeABear () {
		var swiftCode = @"
public enum Size {
    case small, medium, large
    internal func toString () -> String {
        switch self {
        case .small: return ""small""
        case .medium: return ""medium""
        case .large: return ""large""
	}
    }
}

public protocol Bearlike {
	var name:String { get }
	func speak ()
    var size: Size { get }
}

public func describeBear (b: Bearlike)
{
	print (""I am a bear \(b.toString()) named \(b.name)."")
    b.speak ()
}
";
			var altClass = new CSClass (CSVisibility.Public, "FuzzyWuzzy");
			altClass.Inheritance.Add (new CSIdentifier ("IBearlike"));
			var roar = CSFunctionCall.ConsoleWriteLine (CSConstant.Val ("RAwwr!"));
			var speakBody = CSCodeBlock.Create (roar);
			var speak = new CSMethod (CSVisibility.Public, CSMethodKind.None, CSSimpleType.Void, new CSIdentifier ("Speak"), new CSParameterList (), speakBody);
			altClass.Methods.Add (speak);

			var sizeReturn = CSReturn.ReturnLine (new CSIdentifier ("Size.Small"));
			var sizeProp = new CSProperty (new CSSimpleType ("Size"), CSMethodKind.None, new CSIdentifier ("Size"),
				CSVisibility.Public, CSCodeBlock.Create (sizeReturn),
				CSVisibility.Public, null);
			altClass.Properties.Add (sizeProp);

			var nameReturn = CSReturn.ReturnLine (new CSFunctionCall ("SwiftString.FromString", false, CSConstant.Val ("FuzzyWuzzy")));
			var nameProp = new CSProperty (new CSSimpleType ("SwiftString"), CSMethodKind.None, new CSIdentifier ("Name"),
				CSVisibility.Public, CSCodeBlock.Create (nameReturn), CSVisibility.Public, null);
			altClass.Properties.Add (nameProp);

			var ctor = new CSMethod (CSVisibility.Public, CSMethodKind.None, null, new CSIdentifier ("FuzzyWuzzy"), new CSParameterList (),
				CSCodeBlock.Create ());
			altClass.Methods.Add (ctor);

			var bearDecl = CSVariableDeclaration.VarLine ("bear", new CSFunctionCall ("FuzzyWuzzy", true));
			var caller = CSFunctionCall.FunctionCallLine ("TopLevelEntities.DescribeBear", false, new CSIdentifier ("bear"));

			var callingCode = CSCodeBlock.Create (bearDecl, caller);
			TestRunning.TestAndExecute (swiftCode, callingCode, "OK\n", otherClass: altClass);
		}

It crashes after accessing the size property.

@stephen-hawley stephen-hawley self-assigned this Mar 12, 2020
@stephen-hawley stephen-hawley added this to the Future milestone Mar 12, 2020
@stephen-hawley stephen-hawley added the bug Something isn't working label Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant