You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if existing_binding isa Binding && (existing_binding.val isa Binding || existing_binding.val isa SymbolServer.FunctionStore || existing_binding.val isa SymbolServer.DataTypeStore)
330
331
# Should possibly be a while statement
331
332
# If the .val is as above the Binding likely won't have a proper type attached
332
333
# so lets use the .val instead.
333
334
existing_binding = existing_binding.val
334
335
end
335
-
if (existing_binding isa Binding && ((existing_binding.type== CoreTypes.Function || existing_binding.type== CoreTypes.DataType)) || existing_binding isa SymbolServer.FunctionStore || existing_binding isa SymbolServer.DataTypeStore)
336
+
if (existing_binding isa Binding && ((CoreTypes.isfunction(existing_binding.type) ||CoreTypes.isdatatype(existing_binding.type))) || existing_binding isa SymbolServer.FunctionStore || existing_binding isa SymbolServer.DataTypeStore)
336
337
# do nothing name of `x` will resolve to the root method
337
338
else
338
339
seterror!(x, CannotDefineFuncAlreadyHasValue)
@@ -353,7 +354,7 @@ function add_binding(x, state, scope=state.scope)
353
354
check_const_decl(name, b, scope)
354
355
355
356
scope.names[name] = b
356
-
elseifis_soft_scope(scope) &&parentof(scope) isa Scope &&isidentifier(b.name) &&scopehasbinding(parentof(scope), valofid(b.name))
357
+
elseifis_soft_scope(scope) &&parentof(scope) isa Scope &&isidentifier(b.name) &&scopehasbinding(parentof(scope), valofid(b.name))&&!enforce_hard_scope(x, scope)
357
358
add_binding(x, state, scope.parent)
358
359
else
359
360
scope.names[name] = b
@@ -364,6 +365,10 @@ function add_binding(x, state, scope=state.scope)
364
365
end
365
366
end
366
367
368
+
functionenforce_hard_scope(x::EXPR, scope)
369
+
scope.expr.head ===:for&&is_in_fexpr(x, x-> x == scope.expr.args[1])
370
+
end
371
+
367
372
name_is_getfield(x) =parentof(x) isa EXPR &&parentof(parentof(x)) isa EXPR && CSTParser.is_getfield_w_quotenode(parentof(parentof(x)))
368
373
369
374
@@ -393,7 +398,7 @@ function mark_globals(x::EXPR, state)
393
398
end
394
399
395
400
functionname_extends_imported_method(b::Binding)
396
-
if b.type== CoreTypes.Function&& CSTParser.hasparent(b.name) && CSTParser.is_getfield(parentof(b.name))
iscoretype(x::SymbolServer.VarRef, name) = x isa SymbolServer.DataTypeStore && x.name.name == name && x.name isa SymbolServer.VarRef && x.name.parent.name ==:Core
23
+
iscoretype(x::SymbolServer.DataTypeStore, name) = x isa SymbolServer.DataTypeStore && x.name.name.name == name && x.name.name isa SymbolServer.VarRef && x.name.name.parent.name ==:Core
24
+
isdatatype(x) =iscoretype(x, :DataType)
25
+
isfunction(x) =iscoretype(x, :Function)
26
+
ismodule(x) =iscoretype(x, :Module)
27
+
isstring(x) =iscoretype(x, :String)
28
+
ischar(x) =iscoretype(x, :Char)
29
+
issymbol(x) =iscoretype(x, :Symbol)
30
+
@staticif Core.Int == Core.Int64
31
+
isint(x) =iscoretype(x, :Int64)
32
+
else
33
+
isint(x) =iscoretype(x, :Int32)
34
+
end
35
+
isfloat(x) =iscoretype(x, :Float64)
36
+
isvector(x) =iscoretype(x, :Vector)
37
+
isarray(x) =iscoretype(x, :Array)
38
+
isva(x::SymbolServer.FakeUnionAll) =isva(x.body)
39
+
@staticif Core.Vararg isa Core.Type
40
+
functionisva(x)
41
+
return (x isa SymbolServer.FakeTypeName && x.name.name ==:Vararg&&
42
+
x.name.parent isa SymbolServer.VarRef && x.name.parent.name ==:Core)
if (func_ref isa Binding && (func_ref.type === CoreTypes.Function || func_ref.type === CoreTypes.DataType) &&!(func_ref.val isa EXPR && func_ref.val.head ===:macro)) || func_ref isa SymbolServer.FunctionStore || func_ref isa SymbolServer.DataTypeStore
278
+
ifis_something_with_methods(func_ref) &&!(func_ref isa Binding && func_ref.val isa EXPR && func_ref.val.head ===:macro)
287
279
# intentionally empty
288
280
if func_ref isa Binding && func_ref.val isa EXPR &&isassignment(func_ref.val) &&isidentifier(func_ref.val.args[1]) &&isidentifier(func_ref.val.args[2])
289
281
# if func_ref is a shadow binding (for these purposes, an assignment that just changes the name of a mehtod), redirect to the rhs of the assignment.
@@ -438,7 +430,7 @@ function is_never_datatype(b::Binding, server)
438
430
returnis_never_datatype(b.val, server)
439
431
elseif b.val isa SymbolServer.FunctionStore
440
432
returnis_never_datatype(b.val, server)
441
-
elseif b.type== CoreTypes.DataType
433
+
elseifCoreTypes.isdatatype(b.type)
442
434
returnfalse
443
435
elseif b.type !==nothing
444
436
returntrue
@@ -502,6 +494,10 @@ function check_farg_unused_(arg, arg_names)
502
494
returnfalse
503
495
end
504
496
b =bindingof(arg)
497
+
498
+
# We don't care about these
499
+
valof(b.name) isa String &&all_underscore(valof(b.name)) &&returnfalse
500
+
505
501
if b ===nothing||
506
502
# no refs:
507
503
isempty(b.refs) ||
@@ -633,7 +629,7 @@ end
633
629
functionhas_getproperty_method(b::Binding)
634
630
if b.val isa Binding || b.val isa SymbolServer.DataTypeStore
635
631
returnhas_getproperty_method(b.val)
636
-
elseif b isa Binding && b.type=== CoreTypes.DataType
632
+
elseif b isa Binding &&CoreTypes.isdatatype(b.type)
637
633
for ref in b.refs
638
634
if ref isa EXPR &&is_type_of_call_to_getproperty(ref)
639
635
returntrue
@@ -738,7 +734,10 @@ function check_const_decl(name::String, b::Binding, scope)
738
734
seterror!(b.val, CannotDeclareConst)
739
735
else
740
736
prev = scope.names[name]
741
-
if (prev.type === CoreTypes.DataType &&!is_mask_binding_of_datatype(prev)) ||is_const(prev)
737
+
if (CoreTypes.isdatatype(prev.type) &&!is_mask_binding_of_datatype(prev)) ||is_const(prev)
738
+
if b.val isa EXPR && prev.val isa EXPR &&!in_same_if_branch(b.val, prev.val)
739
+
return
740
+
end
742
741
if b.val isa EXPR
743
742
seterror!(b.val, InvalidRedefofConst)
744
743
else
@@ -752,12 +751,12 @@ end
752
751
functionis_mask_binding_of_datatype(b::Binding)
753
752
b.val isa EXPR && CSTParser.isassignment(b.val) && (rhsref =refof(b.val.args[2])) !==nothing&& (rhsref isa SymbolServer.DataTypeStore || (rhsref.val isa EXPR && rhsref.val isa SymbolServer.DataTypeStore) || (rhsref.val isa EXPR && CSTParser.defines_datatype(rhsref.val)))
754
753
end
754
+
755
755
# check whether a and b are in all the same :if blocks and in the same branches
756
-
functionin_same_if_branch(a, b)
757
-
a_branches =find_if_parents(a)
758
-
b_branches =find_if_parents(b)
759
-
760
-
returnlength(a_branches) ==length(b_branches) &&all(k inkeys(b_branches) for k inkeys(a_branches)) &&all(a_branches[k] == b_branches[k] for k inkeys(a_branches))
0 commit comments