Skip to content

Packed tuple and equal unpacked tuple give wrong field values #26424

Open

Description

@etan-status

Nim Version

Nim Compiler Version 2.3.1 [MacOSX: arm64]
Compiled at 2026-10-10
Copyright (c) 2006-2026 by Andreas Rumpf

git hash: b081880000a4d708cdce6afcc4c4124a60a5c62e

Description

type
  Packed {.packed.} = tuple[a: int8, b: int32]
  Plain = tuple[a: int8, b: int32]

var p: Packed = (a: 1'i8, b: 2'i32)
var q: Plain = p
echo q

Current Output

(a: 1, b: 0)

Expected Output

(a: 1, b: 2)

Known Workarounds

No response

Additional Information

Same behaviour on 2.2.12. 2.0.10 prints (a: 1, b: 2).

Activity

  1. Araq commented on Oct 10, 2026

    @Araq
    Member

    .packed on tuples is not a supported feature at all.

  2. added
    Invalid Code AcceptanceEverything related to compiler not complaining about invalid code
    on Oct 10, 2026
  3. etan-status commented on Oct 10, 2026

    @etan-status
    ContributorAuthor

    haha :) Yeah wasn't sure. on UnnamedTuple, pragmas don't make sense, on named ones, they seem to be generally buggy (it's not just {.packed.} but the underlying type conflation issue happens on any pragma)

  4. Araq commented on Oct 10, 2026

    @Araq
    Member

    Tuples are always structural types, the structure defines their identity, every pragma that violates this (importc too) is invalid for tuples.

  5. etan-status commented on Oct 10, 2026

    @etan-status
    ContributorAuthor

    Mmh, the manual itself mentions pragmas on tuples:

    The bycopy pragma can be applied to an object or tuple type or a proc param.

    How to know what pragma violates the structure identity?

    i.e., generally, it seems like the first instance gets picked. So, getCustomPragma etc also is based on the first definition, the later ones (if any) that happen to alias it get wrong answers if they don't match in pragmas.

  6. Araq commented on Oct 15, 2026

    @Araq
    Member

    The manual is wrong too.

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

    Invalid Code AcceptanceEverything related to compiler not complaining about invalid code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions