-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
PropertyError
similar to FieldError
#55298
base: master
Are you sure you want to change the base?
Conversation
At the end of this completed draft we would like update: |
Update: |
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.
With how heavily this function is used, I am very skeptical that we can add any code here without causing problems
@vtjnash True. I sat on it for a while questioning the same. I will bail out as soon as possible and close this when I see concrete evidence that this is impractical. May be you guys see it already. Let me check for myself. |
@@ -450,7 +450,7 @@ JL_DLLEXPORT jl_value_t *jl_get_field(jl_value_t *o, const char *fld) | |||
jl_task_t *ct = jl_current_task; | |||
JL_TRY { | |||
jl_value_t *s = (jl_value_t*)jl_symbol(fld); | |||
int i = jl_field_index((jl_datatype_t*)jl_typeof(o), (jl_sym_t*)s, 1); | |||
int i = jl_field_index((jl_datatype_t*)jl_typeof(o), (jl_sym_t*)s, 2); |
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.
temporary change. Trying to use existing signature.
jl_has_no_field_error(t, fld); | ||
if (err == 2) |
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.
temporary change. Trying to use existing signature. Avoiding more untrackable changes.
update:
julia> struct D
a::Float32
b::Float64
end
julia> d = D(1, 2)
D(1.0f0, 2.0)
julia> d.l
ERROR: PropertyError: instance of type `DataType` has no property `l`
DataType has following properties (:name, :super, :parameters, :types, :instance, :layout, :hash, :flags)
Stacktrace:
[1] getproperty(x::D, f::Symbol)
@ Base ./Base.jl:49
[2] top-level scope
@ REPL[3]:1
julia> d.a
1.0f0
julia> d.b
2.0
julia> D.l
ERROR: FieldError: type DataType has no field l
Stacktrace:
[1] getproperty(x::Type, f::Symbol)
@ Base ./Base.jl:43
[2] top-level scope
@ REPL[6]:1 |
julia> getfield(d, :c)
ERROR: FieldError: type D has no field c
Stacktrace:
[1] top-level scope
@ REPL[7]:1
julia> getproperty(d, :c)
ERROR: PropertyError: instance of type `DataType` has no property `c`
DataType has following properties (:name, :super, :parameters, :types, :instance, :layout, :hash, :flags)
Stacktrace:
[1] getproperty(x::D, f::Symbol)
@ Base ./Base.jl:49
[2] top-level scope
@ REPL[8]:1
@LilithHafner Can I pull you into this ? |
Is your proposed semantic for determining whether to throw a PropertyError or a FieldError equivalent to this: function Base.getproperty(x, f::Symbol)
@inline
res = try
Some(getfield(x, f))
catch ex
ex isa FieldError ? nothing : rethrow()
end
res === nothing && throw(PropertyError(x, f))
getfield(res, :value)
end i.e. throw a property error whenever someone calls getproperty and only throw a field error whenever someone calls getfield directly? |
@LilithHafner Thank you for asking. Thats right. Atleast that was what I am aiming for. I just made a parallel path for objects to raise |
ac4f496
to
1b78e25
Compare
Build should pass locally for anyone who wants to check. |
Quickly wanted to shared with friends and missed inline annotation.
just to satisfy build warning as errors. No good real reason to do so.
update
Base.jl
is unchanged now.And
PropertyError
is duplicate ofFieldError
,nothing special, but code emission is specific to objects instead.