aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-26 10:10:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-26 10:10:41 +0000
commit3802fb92ff8c83eed3e867db20f72c53932f542d (patch)
tree1546344edc8073c122cd47fb567f031a1ebb4551 /parse.y
parent62a3e7a33b24f851bb6c9658925a4bf30655e70c (diff)
downloadruby-3802fb92ff8c83eed3e867db20f72c53932f542d.tar.gz
parse.y: warning for locations
* parse.y (gettable_gen): warn for __FILE__/__LINE__ when eval with binding only. promote use of Binding#source_location instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y18
1 files changed, 18 insertions, 0 deletions
diff --git a/parse.y b/parse.y
index 61fa1aa6a2..9d520cedd4 100644
--- a/parse.y
+++ b/parse.y
@@ -261,6 +261,7 @@ struct parser_params {
unsigned int do_loop: 1;
unsigned int do_chomp: 1;
unsigned int do_split: 1;
+ unsigned int warn_location: 1;
NODE *eval_tree_begin;
NODE *eval_tree;
@@ -9347,6 +9348,13 @@ past_dvar_p(struct parser_params *parser, ID id)
}
# endif
+#define WARN_LOCATION(type) do { \
+ if (parser->warn_location) { \
+ rb_warning0(type" in eval may not return location in binding;" \
+ " use Binding#source_location instead"); \
+ } \
+} while (0)
+
static NODE*
gettable_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
{
@@ -9370,9 +9378,11 @@ gettable_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
nd_set_loc(node, location);
return node;
case keyword__FILE__:
+ WARN_LOCATION("__FILE__");
node = new_str(rb_str_dup(ruby_sourcefile_string), location);
return node;
case keyword__LINE__:
+ WARN_LOCATION("__LINE__");
return new_lit(INT2FIX(tokline), location);
case keyword__ENCODING__:
return new_lit(rb_enc_from_encoding(current_enc), location);
@@ -11527,6 +11537,14 @@ rb_parser_set_options(VALUE vparser, int print, int loop, int chomp, int split)
parser->do_split = split;
}
+void
+rb_parser_warn_location(VALUE vparser, int warn)
+{
+ struct parser_params *parser;
+ TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
+ parser->warn_location = warn;
+}
+
static NODE *
parser_append_options(struct parser_params *parser, NODE *node)
{