Skip to content

fix(instrument): Type names in make/new incorrectly instrumented #34

@kolkov

Description

@kolkov

Problem

When instrumenting code with custom types in make() or new() calls, type names were incorrectly treated as variable reads.

Example:

methods := make([]*SexpFunction, 0)

Generated broken code:

RaceRead(uintptr(unsafe.Pointer(SexpFunction)))  // ERROR: SexpFunction is a TYPE!
methods := make([]*SexpFunction, 0)

This caused compilation error:

SexpFunction (type) is not an expression

Root Cause

extractReads() was walking into type expressions (ArrayType, MapType, etc.) and finding identifiers that looked like variables but were actually type names.

Fix

  1. Added case to skip type expression AST nodes:

    • *ast.ArrayType
    • *ast.MapType
    • *ast.ChanType
    • *ast.StructType
    • *ast.InterfaceType
    • *ast.FuncType
    • *ast.Ellipsis
  2. Special handling for make/new - skip first argument (always a type)

Found While

Testing on zygomys project which uses many custom types with make().

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions