Skip to content

cover fails on OTP 27 with numbered variables #11524

Description

@halostatue

Describe the bug

cover:compile_beam/1 fails on OTP 27 for any function containing an orelse/andalso chain of 3+ comparisons where the chain's variable happens to be named _1, _2, _3, etc. OTP 27 cover's own instrumentation of short-circuit operators introduces synthetic variables using that exact same _N naming scheme, with no check against variables already bound in the code being instrumented. When they collide, the instrumented code is invalid and compile:forms rejects it. cover.erl does not handle that rejection, so the cover:compile_beam/1 call crashes with a badmatch instead of returning {error, _}.

Elixir function captures (&1) are turned into numeric variables (_1) and the Inspect protocol __deriving__ macro triggers this automatically.

To Reproduce

I have a full reproduction (both a bare Erlang reproduction and four separate Elixir reproductions) at https://github.com/halostatue/otp27_cover_repro.

To Fix

Apply @9def2260d1b0 to the OTP 27 maintenance branch.

Expected behavior

Coverage compiling passes (and mix test --cover) passes.

Affected versions

OTP 27 (all). Verified with Elixir 1.20.

Additional context

I have full context and reproduction instructions at https://github.com/halostatue/otp27_cover_repro/blob/main/README.md. This is not reproducible on OTP 28 or OTP 29, but I am unable to upgrade because of issues with an Erlang dependency with incomplete compatibility for either modern OTP version.

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions