Skip to content

Fix "random panic" in DecodeScalar#29

Open
the-eater wants to merge 1 commit intotailhook:mainfrom
the-eater:fix-decode-scalar-panic
Open

Fix "random panic" in DecodeScalar#29
the-eater wants to merge 1 commit intotailhook:mainfrom
the-eater:fix-decode-scalar-panic

Conversation

@the-eater
Copy link
Copy Markdown

Currently you can force a panic while decoding a Value wrapped in a container because all containers delegate decode to the default implementation, while Value only accepts calling decode directly,

This PR makes all containers call ::decode of their child type instead

code proof
use std::rc::Rc;
use knuffel::ast::Value;
use knuffel::span::Span;

fn main() {
    #[derive(Debug, knuffel::Decode)]
    #[knuffel(span_type = Span)]
    struct X {
        #[knuffel(property)]
        d: Rc<Value<Span>>,
    }

    #[derive(Debug, knuffel::Decode)]
    #[knuffel(span_type = Span)]
    struct Document {
        #[knuffel(child)]
        gamer: X,
    }

    let doc = "gamer d=(uwu)\":3\"";

    let parsed: Document = knuffel::parse("<inline>", doc).unwrap();
    println!("{:?}", parsed);
}

I would also like to note that the trait for DecodeScalar seems, confusing?

it's advised not to implement ::decode by hand, however there's no access to the type name in ::raw_decode, requiring weird workarounds to implement a polymorphic scalar while also following said advice

I e.g. currently want to support the following:

match "literal-match" 
match (re)"regex\smatch"

this either requires storing a MyScalarType enum in the context, or not following given advice lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant