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

Combine yields incompatible tuple types #7

Closed
cdlm opened this issue Oct 26, 2020 · 3 comments
Closed

Combine yields incompatible tuple types #7

cdlm opened this issue Oct 26, 2020 · 3 comments

Comments

@cdlm
Copy link

cdlm commented Oct 26, 2020

I was trying to extend your example to also accept #rgb colors, like so:

const rgb = mecha.convert(Rgb, Rgb.from, mecha.combine(.{
    mecha.char('#'),
    mecha.oneOf(.{
        rgbBytes,
        rgbNibbles,
    }),
}));
const rgbBytes = mecha.combine(.{ byte, byte, byte });
const rgbNibbles = mecha.combine(.{ nibble, nibble, nibble });
const byte = mecha.convert(u8, mecha.toInt(u8, 16), mecha.manyRange(2, 2, hex));
const nibble = mecha.convert(u8, mecha.toInt(u8, 16), mecha.manyRange(1, 1, hex));
const hex = mecha.digit(16);

And I'm getting this error when testing: error: expected type '.mecha.Result(.mecha.struct:323:23)', found '.mecha.Result(.mecha.struct:323:23)'
As far as I understand from the code and asking on Discord, combine generates its return type, but rgbBytes and rgbNibbles have distinct tuples even though they are both u8 triplets… (due to @TypeOf)

@cdlm
Copy link
Author

cdlm commented Oct 26, 2020

I worked around it by un-factoring convert from rgb down to rgbBytes and rgbNibbles, so those become Parser(Rgb) and the unique tuple types are immediately consumed.

I'm still wondering if there isn't a better way, but feel free to close.

@Hejsil Hejsil closed this as completed in 3b5bfbc Oct 26, 2020
@Hejsil
Copy link
Owner

Hejsil commented Oct 26, 2020

Good catch. I've pushed a fix that should force the compiler to cache the result of Tuple. I'll have to revisit this once 0.7.0 hits.

@cdlm
Copy link
Author

cdlm commented Oct 26, 2020

👍
I can confirm it allows me to factor the conversion to Rgb back up :-)

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

No branches or pull requests

2 participants