Skip to content

Commit 2184a67

Browse files
vassilmladenovfacebook-github-bot
authored andcommitted
Emit correct position for $c::foo calls
Summary: The logic for emitting a call like `$c::foo()` ends up taking over the srcloc of the call with the srcloc of `$c`, which makes error log lines inconsistent for use in tools like HackAst. Reviewed By: mheiber Differential Revision: D63930673 fbshipit-source-id: 9e984b14345edbdbb62357f137e41cc4118dd195
1 parent c1b2255 commit 2184a67

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

hphp/hack/src/hackc/emitter/emit_expression.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ fn emit_call_default<'a, 'd>(
18601860
scope::with_unnamed_locals(e, |em| {
18611861
let FCallArgs { num_rets, .. } = &fcall_args;
18621862
let num_uninit = num_rets - 1;
1863-
let (lhs, fcall) = emit_call_lhs_and_fcall(em, env, expr, fcall_args, targs, None)?;
1863+
let (lhs, fcall) = emit_call_lhs_and_fcall(em, env, pos, expr, fcall_args, targs, None)?;
18641864
let (args, inout_setters) = emit_args_inout_setters(em, env, args)?;
18651865
let uargs = match uarg {
18661866
Some(uarg) => emit_expr(em, env, uarg)?,
@@ -1994,6 +1994,7 @@ fn emit_object_expr<'a, 'd>(
19941994
fn emit_call_lhs_and_fcall<'a, 'd>(
19951995
e: &mut Emitter<'d>,
19961996
env: &Env<'a>,
1997+
call_pos: &Pos,
19971998
expr: &ast::Expr,
19981999
mut fcall_args: FCallArgs,
19992000
targs: &[ast::Targ],
@@ -2042,7 +2043,7 @@ fn emit_call_lhs_and_fcall<'a, 'd>(
20422043
// handle ObjGet and ClassGet prop call cases. Keep track of the position of the
20432044
// outer readonly expression for use later.
20442045
// TODO: use the fact that this is a readonly call in HHVM enforcement
2045-
emit_call_lhs_and_fcall(e, env, r, fcall_args, targs, Some(pos))
2046+
emit_call_lhs_and_fcall(e, env, call_pos, r, fcall_args, targs, Some(pos))
20462047
}
20472048
Expr_::ObjGet(o) if o.as_ref().3 == ast::PropOrMethod::IsMethod => {
20482049
// Case $x->foo(...).
@@ -2176,10 +2177,13 @@ fn emit_call_lhs_and_fcall<'a, 'd>(
21762177
InstrSeq::gather(vec![
21772178
generics,
21782179
emit_expr(e, env, &expr)?,
2179-
instr::f_call_cls_method_m(
2180-
IsLogAsDynamicCallOp::DontLogAsDynamicCall,
2181-
fcall_args,
2182-
method_name,
2180+
emit_pos_then(
2181+
call_pos,
2182+
instr::f_call_cls_method_m(
2183+
IsLogAsDynamicCallOp::DontLogAsDynamicCall,
2184+
fcall_args,
2185+
method_name,
2186+
),
21832187
),
21842188
]),
21852189
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?hh
2+
3+
class C {
4+
public static function s(string $s): void {}
5+
}
6+
7+
<<__EntryPoint>>
8+
function f(): void {
9+
$c = C::class;
10+
11+
C::s(
12+
$c
13+
); // log line 13
14+
15+
$c::s(
16+
$c
17+
); // should log on 17
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Notice: Implicit Class to string conversion for argument 1 passed to C::s() in %s/class-ptr/class-to-string-log.php on line 13
3+
4+
Notice: Implicit Class to string conversion for argument 1 passed to C::s() in %s/class-ptr/class-to-string-log.php on line 17

0 commit comments

Comments
 (0)