Skip to content

imports: named import with metavariable should recognize unnamed import #2

@abhinav

Description

@abhinav

When trying to match all imports of a path, a patch that specified named imports, even with metavariables will turn unnamed imports into named imports.

Input

Patch:

@@
var foo, x identifier
@@
-import foo "example.com/foo-go.git"
+import foo "example.com/foo.git"

 foo.x

Source:

package whatever

import "example.com/foo-go.git"

func foo() {
  foo.X()
}

Expectation

package whatever

import "example.com/foo-go.git"

func foo() {
  foo.X()
}

Reality

package whatever

import foo "example.com/foo-go.git"

func foo() {
  foo.X()
}

Problem

This is undesirable; the foo metavariable should remember that the import was unnamed and reproduce that. Alternatively, we should provide a different means of matching imports that allows addressing both named and unnamed cases.

Workaround

For now, a workaround is to reproduce the patch as-is twice, once without the named import, once with:

@@
var x identifier
@@
-import "example.com/foo-go.git"
+import "example.com/foo.git"

 foo.x

@@
var foo, x identifier
@@
-import foo "example.com/foo-go.git"
+import foo "example.com/foo.git"

 foo.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions