Skip to content

bug: @type annotation overridden by type inference #1127

Description

@wang573287909

Problem

When using @type annotation to explicitly specify a type, the type inference from assignment statement overrides the annotation type.

Reproduction

---@type ThunderStrikeInviteDataStruct
self.inviteData = nil  -- inferred as nil instead of ThunderStrikeInviteDataStruct

---@type _obj_inviteItem._obj_heroHeadItem_GoTable[]
self.guardObjList = {}  -- inferred as table instead of the specified array type

Expected Behavior

When @type annotation is used, it should take priority over type inference.

Root Cause

In the bind_type function (crates/emmylua_code_analysis/src/compilation/analyzer/common/mod.rs), when an existing type exists, new types are processed through merge_def_type, but it does not properly handle the priority relationship between DocType and InferType.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions