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

Functions accepting SumType!(string, ...) can't accept string #50

Open
denis-sh opened this issue Apr 30, 2020 · 1 comment
Open

Functions accepting SumType!(string, ...) can't accept string #50

denis-sh opened this issue Apr 30, 2020 · 1 comment

Comments

@denis-sh
Copy link

Starting from probably 0.2.0-beta.6 this code fails to compile:

import spasm.bindings;
import spasm.dom;
import spasm.types;

extern (C) export void _start()
{
	import std.algorithm : move;
	
	auto canvas = document.createElement("canvas").as!HTMLCanvasElement;
	document.querySelector("body").front.appendChild(canvas);
	
	auto context = canvas.getContext("2d").front.trustedGet!CanvasRenderingContext2D.move;
	context.fillStyle("green"); // Causes error
	context.fillText("Hello World!", 10, 10);
}

Compilation error:

source/app.d(13,19): Error: template spasm.bindings.html.CanvasRenderingContext2D.fillStyle cannot deduce function from argument types !()(string), candidates are:
/home/denis/.dub/packages/spasm-0.2.0-beta.7/spasm/source/spasm/bindings/html.d(552,8):        fillStyle()(ref scope SumType!(string, CanvasGradient, CanvasPattern) fillStyle)
/home/denis/.dub/packages/spasm-0.2.0-beta.7/spasm/source/spasm/bindings/html.d(555,8):        fillStyle()()
ldc2 failed with exit code 1.

This workaround is needed to call fillStyle and alike functions:

SumType!(string, CanvasGradient, CanvasPattern) color = "green";
context.fillStyle(color);
@skoppe
Copy link
Owner

skoppe commented May 4, 2020

I think it happened because I moved everything to scope ref, you can try to remove it from the fillStyle function to see if that helps.

Another option would be to have the binding generator generate overloads in the presence of SumTypes, and do the conversion for you. Although there might be some that have a lot of combinations.

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

No branches or pull requests

2 participants