Comments (10)
We will change this and implement it just like C# does: only assignments in the constructor will be allowed
from xsharppublic.
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.
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.
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.
This ticket shows exactly this difference in the behavior of the keyword readonly
from xsharppublic.
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.
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.
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.
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.
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)
- Implement GoToBrace action in the VS editor HOT 1
- SQLExec returns -1 even when success
- [VFP dialect] Compatibility: Add an IN clause to the USE command HOT 1
- [Documentation] Add a syntax description of USE commands for VFP dialects. HOT 1
- Collection Class doesn't increase the Count property when adds an item.
- [VFP] Problem with APPEND FROM FOR command HOT 2
- [VFP] Problem with COPY TO ARRAY / DbCopyToArray() with fields of type "G"
- [VFP] Misleading line number reported in compiler error about requiring the /memvar option HOT 1
- [VFP] cannot use the arr[ind1][ind2] syntax to access array members in VFP dialect HOT 3
- [VFP] COPY STRUCTURE FIELDS not recognized
- [VFP] SCATTER/GATHER MEMVAR MEMO not recognized HOT 4
- [VFP] Problems with the INDEX ON command HOT 6
- [VFP] SCATTER/GATHER problem with FIELDS LIKE clause
- [VFP] Missing functions in the runtime
- [VFP] Problem with CURSOR HOT 5
- VS-Integration - Indentation
- FieldPut in a table without data records - Error 5068: There is no current data record, but no exception in VO. HOT 6
- Some issues with indexed PROPERTY SET and ASSIGN HOT 2
- No warning about missing RETURN value in the VO dialect
- Format document no longer working in VS 2022 17.11.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xsharppublic.