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

Constructor calls with generic type argument don't parse correctly #199

Closed
kaleidawave opened this issue Aug 28, 2024 · 0 comments · Fixed by #200
Closed

Constructor calls with generic type argument don't parse correctly #199

kaleidawave opened this issue Aug 28, 2024 · 0 comments · Fixed by #200
Assignees
Labels
bug Something isn't working parser Related to Ezno's syntax parser, AST definitions and output

Comments

@kaleidawave
Copy link
Owner

kaleidawave commented Aug 28, 2024

Given

const y = new Y<3>(3);

It parses as something like:

expression: ConstructorCall {
    constructor: FunctionCall {
        function: VariableReference(
            "Y",
            1003..1004,
        ),
        type_arguments: Some(
            [
                NumberLiteral(
                    Number(
                        3.0,
                    ),
                    1005..1006,
                ),
            ],
        ),
        arguments: [
            Standard(
                NumberLiteral(
                    Number(
                        3.0,
                    ),
                    1008..1009,
                ),
            ),
        ],
        is_optional: false,
        position: 1003..1010,
    },
    type_arguments: None,
    arguments: None,
    position: 999..1010,
},

Something around here (or possibly return precedence) is broken when type arguments show up

let constructor_expression = Self::from_reader_with_precedence(
reader,
state,
options,
FUNCTION_CALL_PRECEDENCE,
Some(start),
)?;
let position = start.union(constructor_expression.get_position());
let (type_arguments, end) = if reader
.conditional_next(|token| *token == TSXToken::OpenChevron)
.is_some()
{
let (generic_arguments, _, end_pos) =
parse_bracketed(reader, state, options, None, TSXToken::CloseChevron)?;
(Some(generic_arguments), end_pos)
} else {
(None, TokenEnd::new(position.end))
};
let (arguments, end) = if reader
.conditional_next(|token| *token == TSXToken::OpenParentheses)
.is_some()
{
parse_bracketed(reader, state, options, None, TSXToken::CloseParentheses)
.map(|(args, _, end)| (Some(args), end))?
} else {
// TODO are type arguments not allowed...?
(None, end)
};
Expression::ConstructorCall {
constructor: constructor_expression.into(),
type_arguments,
arguments,
position: start.union(end),
}

@kaleidawave kaleidawave added bug Something isn't working parser Related to Ezno's syntax parser, AST definitions and output labels Aug 28, 2024
@kaleidawave kaleidawave self-assigned this Aug 28, 2024
kaleidawave added a commit that referenced this issue Aug 29, 2024
- Also adds type check support for it
- Emoji fix in CLI
@kaleidawave kaleidawave linked a pull request Aug 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser Related to Ezno's syntax parser, AST definitions and output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant