typst-community / valkyrie

Type safe type safety for Typst
Other
25 stars 2 forks source link

`auto` in `either` schema is handled like `none` #35

Open tingerrr opened 2 weeks ago

tingerrr commented 2 weeks ago

It seems that c52ae78e1d73105dfc432611e2c790bbf3c12645 introduced a regression where, given an either schema containing an auto schema, passing auto actually fails with an incorrect message saying it got none.

#import "@preview/valkyrie:0.2.0" as z

#{
  _ = z.parse(auto, z.either(
    z.content(),
    z.base-type(name: "auto", types: (type(auto),)),
  ))
}

I haven't actually tested this specific snippet, it's a minified version, I've done the bisection on the actual snippet.

JamesxX commented 2 weeks ago

Tracked the issue down to base-type:

https://github.com/typst-community/valkyrie/blob/35-auto-in-either-schema-is-handled-like-none/src/base-type.typ#L82-L84

I think the most sensible solution would be to provide default: auto when defining the auto schema? that does then mean that passing none as the value makes it mutate into auto.

What are your thoughts? I don't think there's a clean solution