X-Sharp / XSharpPublic

Public repository for the source code for the XSharp Compiler, Runtime, Project System and Tools.
Apache License 2.0
89 stars 36 forks source link

"readonly" error (XBase++) #1490

Open DenGhostYY opened 2 weeks ago

DenGhostYY commented 2 weeks ago

Describe the bug The compiler throws an error due to assignment of a "readonly" field in the context of a method of the same class.

To Reproduce

procedure main()
    local o := Example():new(4)

    ? o:nNumber
//    o:nNumber := 10
    o:SetNumber(15)
    ? o:nNumber
return

class Example
exported:
    var nNumber readonly

    inline method init(nNumber)
        ::nNumber := nNumber
    return

    inline method SetNumber(nNumber)
        ::nNumber := nNumber
    return self
endclass

Expected behavior (XBase++ exe) Output

4
15

Actual behavior (X# compiler)

error XS0191: A readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which the field is defined or a variable initializer)

Additional context X# Compiler version 2.20.0.3 (public) -dialect:xBase++ -codepage:866 -lb -enforceself -memvar -xpp1 -vo1 -vo3 -vo4 -vo5 -vo9 -vo10 -vo12 -vo13 -vo14 -vo15 -vo16 -vo17 -reference:XSharp.Core.dll -reference:XSharp.RT.dll -reference:XSharp.XPP.dll