Skip to content

fix: Nullable.GetValueOrDefault() writes Lua that does not load - #533

Open
mdlsvensson wants to merge 1 commit into
yanghuan:masterfrom
wc3-dev:yh/get-value-or-default
Open

mdlsvensson wants to merge 1 commit into
yanghuan:masterfrom
wc3-dev:yh/get-value-or-default

Conversation

@mdlsvensson

Copy link
Copy Markdown
Contributor
static int Read(int? n) {
  return n.GetValueOrDefault();
}

is written as

return (n or:default())

which is not Lua, so the script does not load.

The template in System.xml took the method's own type argument, and GetValueOrDefault() has none. It now takes the type argument of Nullable<T>:

<method name="GetValueOrDefault" ArgCount="0" Template="({this} or {``0}:default())" />

which gives (n or System.Int32:default()).

Test: NullableTests.GetValueOrDefaultWorks. CI passes: https://github.com/wc3-dev/CSharp.lua/actions/runs/44585226151

The template used the method's type argument ({`0}), which GetValueOrDefault() has none of, so it was written as (n or:default()), which is not Lua. It now uses Nullable<T>'s type argument ({``0}).
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

Successfully merging this pull request may close these issues.

1 participant