Skip to content

[bug] Multi Meta Variable saved as single Meta Variable? #2697

Description

@rcmosher

Please read the FAQ for the bug you encountered.

  • I have read the existing FAQ

⏯ Playground Link

https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImNzaGFycCIsInF1ZXJ5IjoiJE1PRCAkUkVUVVJOX1RZUEUgJEYoJCQkUEFSQU1TKSIsInJld3JpdGUiOiIiLCJzdHJpY3RuZXNzIjoic21hcnQiLCJzZWxlY3RvciI6IiIsImNvbmZpZyI6InJld3JpdGVyczpcclxuLSBpZDogcGFyYW0td3JhcFxyXG4gIHJ1bGU6XHJcbiAgICBraW5kOiBwYXJhbWV0ZXJcclxuICAgIHBhdHRlcm46ICRQXHJcbiAgZml4OlxyXG4gICAgdGVtcGxhdGU6IFwiKiRQXCJcclxucnVsZTpcclxuICBwYXR0ZXJuOiAkJCRQQVJBTVNcclxuICBraW5kOiBwYXJhbWV0ZXJfbGlzdFxyXG50cmFuc2Zvcm06XHJcbiAgUkVQQVJBTTpcclxuICAgIHJld3JpdGU6XHJcbiAgICAgIHJld3JpdGVyczogW3BhcmFtLXdyYXBdXHJcbiAgICAgIHNvdXJjZTogJCQkUEFSQU1TXHJcbmZpeDogJFJFUEFSQU0iLCJzb3VyY2UiOiJwcml2YXRlIHZvaWQgTXlNZXRob2QoaW50IG9uZSwgW0F0dHJpYnV0ZV0gc3RyaW5nIHR3bywgR2VuZXJpYzxBLCBCPiB0d29wb2ludDEsIENsYXNzIHRocmVlKVxue31cblxucHJpdmF0ZSBzdGF0aWMgR2VuZXJpYzxBLCBCLCBDPiBNeU1ldGhvZChpbnQgb25lLCBbQXR0cmlidXRlXSBzdHJpbmcgdHdvLCBHZW5lcmljPEEsIEI+IHR3b3BvaW50MSwgQ2xhc3MgdGhyZWUpXG57fVxuXG5wcml2YXRlIHZvaWQgTm9QYXJhbXMoKVxue31cblxucHJpdmF0ZSB2b2lkIE9uZVBhcmFtKGludCBvbmUpXG57fVxuXG5wcml2YXRlIHZvaWQgVHdvUGFyYW0oaW50IG9uZSwgc3RyaW5nIHR3bylcbnt9XG5cbnByaXZhdGUgdm9pZCBUaHJlZVBhcmFtKGludCBvbmUsIHN0cmluZyB0d28sIG9iamVjdCB0aHJlZSlcbnt9XG5cbk15TWV0aG9kKDEsIFwiaGVsbG9cIiwgbXlPYmosIG90aGVyT2JqKSJ9

💻 Code

private void MyMethod(int one, [Attribute] string two, Generic<A, B> twopoint1, Class three)
{}

private static Generic<A, B, C> MyMethod(int one, [Attribute] string two, Generic<A, B> twopoint1, Class three)
{}

private void NoParams()
{}

private void OneParam(int one)
{}

private void TwoParam(int one, string two)
{}

private void ThreeParam(int one, string two, object three)
{}

MyMethod(1, "hello", myObj, otherObj)

🙁 Actual behavior

The multi meta variable $$$PARAMS does not work as a source for the rewrite. Instead of applying the rewirter to the parameters in the parameter list, the rewrite ends up blank. It appears this is caused by nothing being saved in the multi meta variable, $$$PARAMS

Note: I've kept this example simple to focus on the problem. It is not a useful rewriter.

🙂 Expected behavior

The rewrite should apply to the parameters in the matched parameter list.

Additional information about the issue

This works if a single meta variable is used (playground). Oddly, it also works if the pattern is a multi meta variable, $$$PARAMS, and the source is a single meta variable with the same name, $PARAMS (playgournd) This leads me to believe that the pattern may be getting saved to the single meta variable rather than the multi meta variable.

A multi meta variable does work if instead of using kind a fuller pattern is used on its own for the match (playground). Though it misses one case in the example code due to the pattern choice, which isn't relevant to this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions