Skip to content

gomarkers.py maps the legal Go name "set" to NONAME and exits 0 #131

Open

Description

@soarkit
  • Repository: pingdotgg/ts-rust
  • Target commit: 2082e2a39fb093a14b5215134dc6c09c51450b7f
  • File: scripts/goport/gomarkers.py:332

Summary

gomarkers.py filters marker names against a STOP list using a case-insensitive comparison (name.lower() in {s.lower() ...}). Go identifiers are case-sensitive, so the legal function name set collides with the stop word Set: the marker is classified NONAME and the script exits 0 without checking the reference. The control reference Set is checked and exits 1, showing the list was meant to exclude the exact identifier, not every case variant.

Affected code

scripts/goport/gomarkers.py:

  324      name = name.strip('`')
  325      m = re.match(r'^\((?:\w+\s)?\*?([A-Za-z_]\w*)(?:\[[^\]]*\])?\)\.?\s?([A-Za-z_]\w*)', name) or \
  326          re.match(r'^([A-Za-z_]\w*)\.([A-Za-z_]\w*)(?![\w.])', name)
  327      if m:
  328          return m.group(2), m.group(1)
  329      m = re.match(r'^[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)+', name)  # a chain `a.b.F(...)`: F
  330      if m:
  331          return m.group(0).rsplit('.', 1)[1], None
  332      m = re.match(r'^([A-Za-z_]\w*)', name)
  333      return (m.group(1), None) if m and m.group(1) not in STOP else (None, None)
  334  
  335  
  336  headers = {}
  337  
  338  
  339  def files_for(rf, root, path, pinned):
  340      """(Go files, tag) for a ref: the tree, else the Go toolchain or x/sys."""
  341      c = candidates(root, path)
  342      if c or pinned:
  343          return c, ''
  344      if rf not in headers:

Expected behavior

A valid marker name that is a legal Go identifier, including a lowercase common word such as set, must be checked; it must not be silently downgraded to NONAME.

Actual behavior

A marker such as x.go:1 set or x.go:1 set`` names a valid Go symbol but is treated as having no name because set is in STOP, so the checker exits successfully without validating the ref.

How to reproduce

Run gomarkers.py --verbose --go <dir> on a file containing func set() {} and the marker // Go: x.go:1 set; it prints NONAME and exits 0.

Root cause

gomarkers.py filters marker names against a STOP list using a case-insensitive comparison (name.lower() in {s.lower() ...}). Go identifiers are case-sensitive, so the legal function name set collides with the stop word Set: the marker is classified NONAME and the script exits 0 without checking the reference. The control reference Set is checked and exits 1, showing the list was meant to exclude the exact identifier, not every case variant.

Suggested fix

Compare the marker name case-sensitively against the stop list (or store exact identifiers in the list):

if marker_name in STOP:  # not marker_name.lower() in {s.lower() ...}
    ...

Add a test with func set() {} and the marker // Go: x.go:1 set asserting it is checked (STALE/NOTFOUND), not NONAME.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions