dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
589 stars 52 forks source link

Struct copy handling issues #1399

Open Jooseppi12 opened 3 months ago

Jooseppi12 commented 3 months ago

Given the following F# code:

[<Struct>]
type Position =
    {
        pos_fname: string
        pos_lnum: int
        pos_orig_lnum: int
        pos_bol: int
        pos_cnum: int
    }

    member pos.FileName = pos.pos_fname

    member pos.Line = pos.pos_lnum

    member pos.OriginalLine = pos.pos_orig_lnum

    member pos.Char = pos.pos_cnum

    member pos.AbsoluteOffset = pos.pos_cnum

    member pos.StartOfLine = pos.pos_bol

    member pos.StartOfLineAbsoluteOffset = pos.pos_bol

    member pos.Column = pos.pos_cnum - pos.pos_bol

    member pos.NextLine =
        { pos with
            pos_orig_lnum = pos.OriginalLine + 1
            pos_lnum = pos.Line + 1
            pos_bol = pos.AbsoluteOffset
        }

    member this.EndOfToken(n) =
        let pos = this
        { pos with pos_cnum = pos.pos_cnum + n }

    member pos.AsNewLinePos() = pos.NextLine

    member this.ShiftColumnBy(by) =
        let pos = this
        { pos with
            pos_cnum = pos.pos_cnum + by
        }

    static member Empty =
        {
            pos_fname = ""
            pos_lnum = 0
            pos_orig_lnum = 0
            pos_bol = 0
            pos_cnum = 0
        }

    static member FirstLine(filename) =
        {
            pos_fname = filename
            pos_orig_lnum = 1
            pos_lnum = 1
            pos_bol = 0
            pos_cnum = 0
        }

we end up with code generated with MISSINGVAR like this:

get NextLine(){
    const i={get:() => this, set:(v) => {
      MISSINGVARthis_1=v;
    }};
    const p=this.OriginalLine+1;
    return _c_30.New(i.pos_fname, this.Line+1, p, this.AbsoluteOffset, i.pos_cnum);
  }