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

WIG Pattern.OptionalFields accessing wrong property #1115

Closed
dvdkon opened this issue Nov 15, 2020 · 4 comments
Closed

WIG Pattern.OptionalFields accessing wrong property #1115

dvdkon opened this issue Nov 15, 2020 · 4 comments
Assignees

Comments

@dvdkon
Copy link

dvdkon commented Nov 15, 2020

When a property is generated by Pattern.OptionalFields, accessing the "...Opt" variant should translate to accessing the base-name property in JavaScript. Due to a bug, the resulting JS code accesses the non-existent "...Opt" property.

Sample WIG F# code:

let C1 =
    Class "C1"
    |+> Pattern.OptionalFields [
        "field", T<int>
    ]

Resultant .DLL decompiled to C#:

public class C1 {
	public Optional<int> FieldOpt {
		[Inline("$this.fieldOpt")]
		get {
			throw new NotImplementedException();
		}
		[Inline("$wsruntime.SetOrDelete($this, 'fieldOpt', $value)")]
		set {
			throw new NotImplementedException();
		}
	}

	public int Field {
		[Inline("void ($this.field = $value)")]
		set {
			throw new NotImplementedException();
		}
	}
}

Note how the Inline annotation contains fieldOpt, when it should contain just field.

I tried to fix this myself, but I couldn't get WebSharper to build. All it should take as far as I know is WithSourceName in the function.

@granicz
Copy link
Member

granicz commented Nov 18, 2020

@dvdkon Thanks for the report! First and foremost is to figure out why the repo wouldn't build for you. Could you post the error you are seeing on a separate ticket? Thanks!

@dvdkon
Copy link
Author

dvdkon commented Nov 20, 2020

All right, here's the issue number: #1118

@Jand42
Copy link
Member

Jand42 commented Nov 23, 2020

@dvdkon Thanks for the report, fix will be in next release soon.
Workaround:
Define OptionalFields helper for yourself, it's just a convenience tool built upon other public WIG API operators and functions.

    let OptionalFields (optional: seq<string * Type.Type>) =
        Instance [
            for (n, t) in optional do
                yield n =! t :> _
                let sn =
                    let name = n.Replace('.', '_')
                    name.Substring(0, 1).ToUpper() + name.Substring 1 + "Opt"
                yield n =@ !?t |> WithSourceName sn :> _
        ]

@Jand42
Copy link
Member

Jand42 commented Dec 7, 2020

@Jand42 Jand42 closed this as completed Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants