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

Compiler incorrectly infers types when nesting functions #328

Open
fmoo opened this issue Aug 16, 2022 · 2 comments
Open

Compiler incorrectly infers types when nesting functions #328

fmoo opened this issue Aug 16, 2022 · 2 comments
Assignees
Labels

Comments

@fmoo
Copy link

fmoo commented Aug 16, 2022

What is the current behavior?

When nesting functions, the compiler cannot correctly infer the type of the inner function in order to invoke the outer one.

A yarn error is shown in Unity. The error is also shown in the vscode extension

Please provide the steps to reproduce, and if possible a minimal demo of the problem:

Given the following custom functions:

// using System.Linq;
runner.AddFunction<string>("guid", () => System.Guid.NewGuid().ToString());
runner.AddFunction<string, string>("reverse", (s) => new string(s.Reverse().ToArray()));

Called as such:

<<declare $_spam = "">>
<<set $_spam = reverse(guid())>>

The following error is raised in Unity:

Error compiling: 13:15: Error: reverse parameter 1 expects a undefined, not a undefined
reverse(guid())

The following error is raised in vscode:

Could not find function definition for reverse(YRNMsngCmdDef)
reverse parameter 1 expects a undefined, not a undefined

What is the expected behavior?

There should be no errors shown in unity or vscode for this scenario.

Please tell us about your environment:

  • Yarn Spinner Version: 2.2
  • Unity Version: 2021.1.18f1

Other information

@fmoo fmoo added the bug label Aug 16, 2022
@fmoo fmoo changed the title Compiler fails when nesting functions Compiler incorrectly infers types when nesting functions Aug 16, 2022
@fmoo
Copy link
Author

fmoo commented Aug 16, 2022

Also repros on vscode extension v2.2.40

@McJones
Copy link
Collaborator

McJones commented Feb 1, 2024

This issue has been a weird one for a while and have made some progress.
This comment is more for my own records while this issue is still being worked on.

This isn't being caused by nesting, but is something to do with the registered type inference, but weirder still only when using the AddFunction call on the dialogue runner.

So the following yarn:

<<declare $_spam = "">>
<<set $_spam = reverse("value")>>

does not work if you declare the function via the following code:

runner.AddFunction<string, string>("reverse", (s) => new string(s.Reverse().ToArray()));

but will work fine if you do it like this:

[YarnFunction("reverse")]
public static string Reverse(string value)
{
    return new string(value.Reverse().ToArray());
}

This occurs both on mainline YS/VSCode but also on the WIP 3.0 branch with the improved type system there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants