Skip to content

Second (or later) init() or _() gets no L3 or L4 output #76

Done

Description

@rahlk

Describe the bug
Again on PR #55, related to #75. We store the second func init() in a file under the signature <pkg>.init:2. Now, L3 and L4 stages do their look ups by declaration with (file, SignatureOf(obj)). This will give us <pkg>.init for every init. The look up for init will always give us init (the first one) regardless of how many inits there actually are. But when this happens, the start line of the actual init and what we got do not match and the analyzer skips this entirely.

The second init then has no cfg, cdg, ddg or L4 vertices. Its body has no @entry and no @exit. Nothing goes into degraded[], and --strict does not fail.

To Reproduce
Steps to reproduce:

  1. Use the two-init project from the closure issue (one main.go, two func init(), each with a closure).
  2. Run cango -i . -a 3 -o out.
  3. Look at main.go/init:2 in out/analysis.json.

Expected behavior
init:2 has the same L3 facts as init: @entry, @exit and a cfg. If L3 cannot be built, an entry in degraded[] names it.

Logs
From a build of PR #55 head (d2ae0e4):

main.go/init    lines 5-8    cfg 4   body {6:2, 7:2, @entry, @exit}
main.go/init:2  lines 10-13  cfg 0   body {12:2}
degraded: none

Additional context

  • L3: internal/syntactic_analysis/l3units.go:70. The key uses b.declSignature(pkg, fd), which has no :N. byKey has init and init:2, so the second FuncDecl matches the first init, fails the StartLine check and is skipped with no warning.
  • L4: internal/sdg/join.go:244 (declKey) has the same mismatch, so the SSA function of the second init does not join to a unit.
  • Possible fix: one helper that maps a FuncDecl to its symbol-table signature (with the :N), used by the symbol table, L3Units and declKey. Alternatively, key these maps by declaration position.
  • Related Closures of a second function init() or _() happens to merge with the closures of the first #75

Activity

  1. added
    bug
    on Nov 29, 2026
  2. changed the title [-]Second (or later) `init()` gets no L3 or L4 output[/-] [+]Second (or later) `init()` or `_()` gets no L3 or L4 output[/+] on Nov 29, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions