Skip to content

Commit 5dcd469

Browse files
committed
improve inference of T.mutable field access
1 parent 4808eda commit 5dcd469

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/inference.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ const DataType_name_fieldindex = fieldindex(DataType, :name)
13311331
const DataType_parameters_fieldindex = fieldindex(DataType, :parameters)
13321332
const DataType_types_fieldindex = fieldindex(DataType, :types)
13331333
const DataType_super_fieldindex = fieldindex(DataType, :super)
1334+
const DataType_mutable_fieldindex = fieldindex(DataType, :mutable)
13341335

13351336
const TypeName_name_fieldindex = fieldindex(TypeName, :name)
13361337
const TypeName_module_fieldindex = fieldindex(TypeName, :module)
@@ -1340,7 +1341,8 @@ function const_datatype_getfield_tfunc(sv, fld)
13401341
if (fld == DataType_name_fieldindex ||
13411342
fld == DataType_parameters_fieldindex ||
13421343
fld == DataType_types_fieldindex ||
1343-
fld == DataType_super_fieldindex)
1344+
fld == DataType_super_fieldindex ||
1345+
fld == DataType_mutable_fieldindex)
13441346
return abstract_eval_constant(getfield(sv, fld))
13451347
end
13461348
return nothing

test/inference.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,3 +1300,8 @@ g_test_constant() = (f_constant(3) == 3 && f_constant(4) == 4 ? true : "BAD")
13001300

13011301
f_pure_add() = (1 + 1 == 2) ? true : "FAIL"
13021302
@test @inferred f_pure_add()
1303+
1304+
# inference of `T.mutable`
1305+
@test Core.Inference.getfield_tfunc(Const(Int), Const(:mutable)) == Const(false)
1306+
@test Core.Inference.getfield_tfunc(Const(Vector{Int}), Const(:mutable)) == Const(true)
1307+
@test Core.Inference.getfield_tfunc(DataType, Const(:mutable)) == Bool

0 commit comments

Comments
 (0)