semgrep icon indicating copy to clipboard operation
semgrep copied to clipboard

[scala] Infer object type for metavariables from object creation if type is not present

Open Strunevskiy opened this issue 3 years ago • 7 comments

Is your feature request related to a problem? Please describe. It would be nice to be able to search for the usage of method calls on particular objects. But scala is not strictly typed language and when type is missed some metavariables do not work, for example: invocation of method makeBean on the object MapToBeanMapperImpl() for the example below.

val mapper =  MapToBeanMapperImpl()

($OBJECT : MapToBeanMapperImpl).makeBean

There could be object inheritance, but we could start simple, just take object type on the right.

Describe the solution you'd like A clear and concise description of what you want to happen. https://semgrep.dev/s/eEz0

Describe alternatives you've considered when I need to search for method invocation, I just create patterns to search for object init.

Use case This will allow us to perform better scan for method usage on objects.

Strunevskiy avatar Jun 16 '22 05:06 Strunevskiy

This issue is synced in Linear at https://linear.app/r2c/issue/PA-1513/infer-object-type-for-metavariables-from-object-creation-if-type-is. Note: this link is for r2c use only and is not accessible publicly.

r2c-demo avatar Jun 16 '22 05:06 r2c-demo

Note that that's something DeepSemgrep was designed for.

aryx avatar Jun 16 '22 10:06 aryx

@aryx what is deep semgrep ? could you share any link ?

Strunevskiy avatar Jun 16 '22 15:06 Strunevskiy

https://r2c.dev/blog/2022/introducing-deepSemgrep/

aryx avatar Jun 16 '22 16:06 aryx

but we can still independently do a best effort for semgrep and try to match the function name to the type in that case. It's nice that scala does not need x = new Foo(), but for us it makes things harder :)

aryx avatar Jun 16 '22 16:06 aryx

This issue is being marked stale because there hasn't been any activity in 14 days and either it wasn't prioritized or its priority is high. Please apply the appropriate priority:* label before removing the stale label.

stale[bot] avatar Jul 02 '22 03:07 stale[bot]

Stale-bot has closed this stale item. Please reopen it if this is in error.

stale[bot] avatar Jul 10 '22 04:07 stale[bot]