Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default value not checked if the typespec is missing #45

Open
meox opened this issue Nov 27, 2023 · 2 comments
Open

default value not checked if the typespec is missing #45

meox opened this issue Nov 27, 2023 · 2 comments
Labels
T:Bug Type: Bug

Comments

@meox
Copy link

meox commented Nov 27, 2023

I have a typedstruct defined in this way:

defmodule Msg do
    use TypedStruct

    typedstruct do
      field(:version, default: 1)
      field(:note, String.t(), default: "")
    end
end

If I default construct the record in this way: %Msg{} I got

%Msg{version: nil, note: ""}

instead of

%Msg{version: 1, note: ""}

Specifying the typespec everything works as expected.

@leggebroten
Copy link

Consider this plugin

  • typed_struct_ctor
    – Adds validating (new and from) constructor functions.

    Try the macro out in real time without having to install or write any of your own code.
    All you need is a running instance of Livebook

    Run in Livebook

@ejpcmac
Copy link
Owner

ejpcmac commented Dec 29, 2023

Hello @meox, this is indeed a bug: we should check that the second argument to field/2 is a type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T:Bug Type: Bug
Projects
Status: Backlog
Development

No branches or pull requests

3 participants