Skip to content

Possible Bug: Incomplete Function Analysis with refAllDecls #22953

@kython28

Description

@kython28

Zig Version

0.14.0-dev.3267+59dc15fa0

Steps to Reproduce and Observed Behavior

I'm currently migrating my codebase from Zig 0.13.0 to 0.14.0-dev.3267+59dc15fa0, and I've noticed what might be unexpected behavior in the semantic analysis of functions.

In my test file, I'm using std.testing.refAllDecls which, as far as I understand, should trigger semantic analysis for all declarations. While this generally works as expected, I've observed that some functions seem to be skipped during analysis.

To reproduce:

  1. Check my repository's test file at tests/main.zig
  2. Notice the line std.testing.refAllDecls(opencl.errors); which should analyze all declarations (src/errors.zig)
  3. Specifically, there's a public function translate_opencl_error_for_all_fields that contains:
const opencl_error_fields = @typeInfo(opencl_error_enum).Enum.fields;

This should trigger an error as the correct syntax should be:

const opencl_error_fields = @typeInfo(opencl_error_enum).@"enum".fields;
  1. The semantic analysis also fails to detect this issue when trying to reference it with _ = &opencl.errors.translate_opencl_error_for_all_fields
  2. The only way to trigger the analysis is by directly calling the function: opencl.errors.translate_opencl_error_for_all_fields(0);

Question: Shouldn't refAllDecls trigger semantic analysis for all declarations? Is this intended behavior or potentially a bug?

I'm not entirely sure if this is a bug or if I'm misunderstanding how refAllDecls is supposed to work. Any clarification would be appreciated.

Expected Behavior

The compiler should detect and report that .Enum is an invalid field access or something like that

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions