Skip to content

Dynamic struct keys not allowed: "error: invalid key field for struct, struct keys must be atoms" #15834

Description

@azizk

Existing issue

  • I have searched existing issues and could not find a duplicate.

Elixir and Erlang/OTP versions

Erlang/OTP 29 [erts-17.0.6] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.20.4 (compiled with Erlang/OTP 29)

Operating system

NixOS

Current behavior

Dynamic key variables are not allowed in a struct:

field = :path
%URI{field => "/"}

And always produce the following error:

error: invalid key field for struct, struct keys must be atoms, got: 
└─ iex:1

** (CompileError) cannot compile code (errors have been logged)

Expected behavior

This here on the other hand just works:

field = :path
%{%URI{} | field => "/"}

Would be good if it worked directly.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions