Skip to content

Commit

Permalink
Constant propagation of this.field (semgrep#2283)
Browse files Browse the repository at this point in the history
Fixes semgrep#2247

test plan:
test file included
  • Loading branch information
Yoann Padioleau authored Dec 17, 2020
1 parent ed32879 commit 4aa2a46
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
- Support for '...' in chains of method calls in JS, e.g. `$O.foo() ... .bar()`
- typed metavariables can now match field access when we can propagate
the type of a field
- Constant propagation for Java final fields (using this.field syntax)
- Official Ruby GA support

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion semgrep-core/matching/Normalize_generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ let normalize_import_opt is_pattern i =
let rec eval x =
match x with
| L x -> Some x
| Id (_, { id_const_literal = {contents = Some x}; _}) -> Some x
| Id (_, { id_const_literal = {contents = Some x}; _})
(* todo: Java does not generate a special This! use Id *)
| DotAccess ((IdSpecial (This, _) | Id(("this", _), _)),
_, EId (_, {id_const_literal = {contents = Some x}; _})) ->
Some x

| Call(IdSpecial((Op(Plus | Concat) | ConcatString _), _), args)->
let literals = args |> unbracket |> Common.map_filter (fun (arg) ->
Expand Down
2 changes: 1 addition & 1 deletion semgrep-core/pfff
Submodule pfff updated from ac5c2a to 1779e8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Foo {
private final String FIELD = "password";

void test() {
//ERROR: match
foo(FIELD);

//ERROR: match
foo(this.FIELD);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo("password")

0 comments on commit 4aa2a46

Please sign in to comment.