-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
progess default field #19755
progess default field #19755
Conversation
3628336
to
51d616d
Compare
It is quite complex... |
It seems that now I need to add a flag to handle fieldVisible issue... |
As a bonus, range defined in the object seem to work now(namely DateTime can be used as an object attribute) ignoring the field visible issue. |
7be8c57
to
0b32c96
Compare
234f4c3
to
2cf87ec
Compare
2cf87ec
to
ad67b71
Compare
@@ -502,6 +502,7 @@ type | |||
nfLastRead # this node is a last read | |||
nfFirstWrite# this node is a first write | |||
nfHasComment # node has a comment | |||
nfUseDefaultField |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a better way, query sym.ast
and see if it contains a value and not nkEmpty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag is to solve field visible problem.
Default* = object
poi: int = 12
clc: Clean
se*: range[0'i32 .. high(int32)]
poi is not a public object attribute. For a object construct in other modules, I need to distinguish default construct from manual construct.
Default()
should pass while Default(poi: 15)
should raise. And The ast of Default
isn't empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand your remark. What does it mean "it should raise"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flag is used to indicate that this field has been used as the default object construction so that the semConstr won't issues an error for private fields.
For example, I have a a.nim
module which has a Default
object with private fields.
# a.nim
type
Default* = object
id: int = 1
Now I imports it in the b.nim
module. var x: Default
will be transformed into var x: Default = Default(id: 1)
. id
is a private field, we need to use .ast != nil
or
a new flag to let the compiler allow this.
# b.nim
import a
var x: Default
However .ast != nil
doesn't work in the case that users use the id
field wrongly. Even if id
is a private field, users can still use it in the other modules, which causes confusion.
# b.nim
import a
var x = Default(id: 10)
Using .ast != nil
cannot distinguish the two cases.
succeeded by #20220 |
inspired by #12378
default fields for object
the addition compared to #12378
notes for me only
abstractInst vs {tyGenericInst, tyAlias, tySink}