Giter VIP home page Giter VIP logo

Comments (10)

RobertvanderHulst avatar RobertvanderHulst commented on August 23, 2024

We will change this and implement it just like C# does: only assignments in the constructor will be allowed

from xsharppublic.

DenGhostYY avatar DenGhostYY commented on August 23, 2024

If you implement this as in C#, then a lot of legacy Alaska code will not compile on XSharp. We planned to replace the readonly (if there are any difficulties with it) with the assignment hidden|protected.

from xsharppublic.

RobertvanderHulst avatar RobertvanderHulst commented on August 23, 2024

If you implement this as in C#, then a lot of legacy Alaska code will not compile on XSharp. We planned to replace the readonly (if there are any difficulties with it) with the assignment hidden|protected.

Why would that not work?

from xsharppublic.

DenGhostYY avatar DenGhostYY commented on August 23, 2024

Because at the moment class fields marked with readonly can only be assigned inside a constructor, but not inside methods of the same class, although Alaska allows this.

from xsharppublic.

DenGhostYY avatar DenGhostYY commented on August 23, 2024

This ticket shows exactly this difference in the behavior of the keyword readonly

from xsharppublic.

RobertvanderHulst avatar RobertvanderHulst commented on August 23, 2024

Ok, so the readonly modifier describes a field that acts like a property in C# with public get, private set.
The easiest way to implement this would be an auto property with public get private set. Would that be OK?

from xsharppublic.

DenGhostYY avatar DenGhostYY commented on August 23, 2024

From Alaska documentation about the readonly

The option READONLY limits write access for an instance variable. The assignment of a value to an instance variable declared READONLY is only permitted within the source code of methods. If the instance variable has global visibility (visibility attribute EXPORTED:), an assignment can be made within methods of the class and its subclasses. If the visibility attribute is PROTECTED:, READONLY limits the assignment to the methods of the declared class.

That is, depending on the visibility of the field, the assignment area will also change

from xsharppublic.

RobertvanderHulst avatar RobertvanderHulst commented on August 23, 2024

DotNet does not have a different visibility for GET/SET for fields (class variables)
So we will have to translate

exported:
var nNumber assignment hidden

into an auto property with a different visibility for the setter and getter

in X# Core class syntax that would become

class Example
    public property nNumber as USUAL AUTO GET HIDDEN SET
    constructor(nNumber)
        ::nNumber := nNumber
    METHOD SetNumber(nNumber)
        ::nNumber := nNumber
        RETURN SELF
end class

and that will result in a runtime error when assigning the number like in this code

o:nNumber := 10

from xsharppublic.

DenGhostYY avatar DenGhostYY commented on August 23, 2024

Perfect solution. Then the same solution can be applied for the keyword readonly #1490.

Yes, this assignment o:nNumber := 10 ends in a runtime error in alaska.

from xsharppublic.

nvkokkalis avatar nvkokkalis commented on August 23, 2024

Robert, this solution does not fully work as expected. There is neither a compile-time nor a runtime error.

The compiler throws no error because the member access is late-bound and the compiler is happy to translate o:nNumber := 10 to an IVarPut() call.

No runtime error is thrown either (!!!), although the assignment itself is not executed. So, the output of the sample becomes:

4
15

Also, note that since it is now a property the address-of operator won't work on it (if that's applicable). It should work when passed as a ref-argument, though.

from xsharppublic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.