@@ -985,25 +985,31 @@ int jl_in_vinfo_array(jl_array_t *a, jl_sym_t *v)
985
985
return 0 ;
986
986
}
987
987
988
- static int in_sym_array (jl_array_t * a , jl_value_t * v )
988
+ int jl_in_sym_array (jl_array_t * a , jl_sym_t * v )
989
989
{
990
990
size_t i , l = jl_array_len (a );
991
991
for (i = 0 ; i < l ; i ++ ) {
992
- if (jl_cellref (a ,i ) == v )
992
+ if (jl_cellref (a ,i ) == ( jl_value_t * ) v )
993
993
return 1 ;
994
994
}
995
995
return 0 ;
996
996
}
997
997
998
+ int jl_local_in_ast (jl_expr_t * ast , jl_sym_t * sym )
999
+ {
1000
+ return jl_in_vinfo_array (jl_lam_vinfo (ast ), sym ) ||
1001
+ jl_in_vinfo_array (jl_lam_capt (ast ), sym ) ||
1002
+ jl_in_sym_array (jl_lam_staticparams (ast ), sym );
1003
+ }
1004
+
1005
+ JL_CALLABLE (jl_f_get_field );
1006
+
998
1007
static jl_value_t * resolve_globals (jl_value_t * expr , jl_lambda_info_t * lam )
999
1008
{
1000
1009
if (jl_is_symbol (expr )) {
1001
1010
if (lam -> module == NULL )
1002
1011
return expr ;
1003
- int is_local = jl_in_vinfo_array (jl_lam_vinfo ((jl_expr_t * )lam -> ast ), (jl_sym_t * )expr ) ||
1004
- jl_in_vinfo_array (jl_lam_capt ((jl_expr_t * )lam -> ast ), (jl_sym_t * )expr ) ||
1005
- in_sym_array (jl_lam_staticparams ((jl_expr_t * )lam -> ast ), expr );
1006
- if (!is_local )
1012
+ if (!jl_local_in_ast ((jl_expr_t * )lam -> ast , (jl_sym_t * )expr ))
1007
1013
return jl_module_globalref (lam -> module , (jl_sym_t * )expr );
1008
1014
}
1009
1015
else if (jl_is_lambda_info (expr )) {
@@ -1020,6 +1026,21 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_lambda_info_t *lam)
1020
1026
e -> head == line_sym || e -> head == meta_sym ) {
1021
1027
}
1022
1028
else {
1029
+ if (e -> head == call_sym && jl_expr_nargs (e ) == 3 && jl_is_quotenode (jl_exprarg (e ,2 )) &&
1030
+ lam -> module != NULL ) {
1031
+ // replace getfield(module_expr, :sym) with GlobalRef
1032
+ jl_value_t * s = jl_fieldref (jl_exprarg (e ,2 ),0 );
1033
+ if (jl_is_symbol (s )) {
1034
+ jl_value_t * f = jl_static_eval (jl_exprarg (e ,0 ), NULL , lam -> module ,
1035
+ NULL , (jl_expr_t * )lam -> ast , 0 , 0 );
1036
+ if (f && jl_is_func (f ) && ((jl_function_t * )f )-> fptr == & jl_f_get_field ) {
1037
+ jl_value_t * m = jl_static_eval (jl_exprarg (e ,1 ), NULL , lam -> module ,
1038
+ NULL , (jl_expr_t * )lam -> ast , 0 , 0 );
1039
+ if (m && jl_is_module (m ))
1040
+ return jl_module_globalref ((jl_module_t * )m , (jl_sym_t * )s );
1041
+ }
1042
+ }
1043
+ }
1023
1044
size_t i = 0 ;
1024
1045
if (e -> head == method_sym || e -> head == abstracttype_sym || e -> head == compositetype_sym ||
1025
1046
e -> head == bitstype_sym || e -> head == macro_sym || e -> head == module_sym )
5 commit comments
staticfloat commentedon Jul 23, 2015
Is it intended that this change disables the ability to have functions that shadow
Base
functions in a module? E.g. ifHomebrew.jl
were to define aninfo()
function that shadowsBase.info()
? See JuliaPackaging/Homebrew.jl#90 for more.JeffBezanson commentedon Jul 23, 2015
No, that was caused by an earlier change (#4345). However I'm considering allowing shadowing
using Base
(see #12183).kmsquire commentedon Jul 23, 2015
git bisect showed this commit to be the cause.
JeffBezanson commentedon Jul 23, 2015
Oh dear. That was not the intention.
JeffBezanson commentedon Jul 23, 2015
Should be fixed now.