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

Report diagnostics in Type::from_ast #5

Closed
pzipper opened this issue Jun 2, 2023 · 0 comments
Closed

Report diagnostics in Type::from_ast #5

pzipper opened this issue Jun 2, 2023 · 0 comments
Assignees
Labels
A-diagnostics Area: diagnostics A-sema Area: the semantic analysis phase on the AST B-none Breaks: nothing, updates are internal and/or don't change existing features C-bug-report Category: bug report P-high Priority: should ship in the earliest possible release
Milestone

Comments

@pzipper
Copy link
Member

pzipper commented Jun 2, 2023

Currently, Type::from_ast looks like this:

from (src/types.rs):

/// Attempts to resolve a constant type value from the provided expression.
pub fn from_ast(
    cx: &mut Context,
    unit: &mut Unit,
    scope: &Scope,
    expr: &ast::Expr,
) -> Result<Self, ()> {
    let Value::Type(final_ty) = Value::eval(
        IntermediateExpr::verify(cx, unit, scope, expr)?
            // verify that the value is a type
            .coerce(&Type::Type)
            .expect("TODO: report non-type in type position"),
    )
    .expect("TODO: report non-constant type")
    else { 
        unreachable!("value should be of type `type` as verified above")
    };

    Ok(final_ty)
}

Rather than expecting and panicking when a value is used as a type, we should report a diagnostic. Ideally, this diagnostic would be a type-mismatch diagnostic which may be re-used in other situations, such as variable type mismatches, etc.

@pzipper pzipper added A-sema Area: the semantic analysis phase on the AST B-none Breaks: nothing, updates are internal and/or don't change existing features C-bug-report Category: bug report A-diagnostics Area: diagnostics labels Jun 2, 2023
@pzipper pzipper added this to the 0.5.0-alpha milestone Jun 2, 2023
@pzipper pzipper self-assigned this Jun 2, 2023
@pzipper pzipper added the P-high Priority: should ship in the earliest possible release label Jun 2, 2023
@pzipper pzipper changed the title Report diagnostics Report diagnostics in Type::from_ast Jun 2, 2023
@pzipper pzipper closed this as completed in f15e5b8 Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: diagnostics A-sema Area: the semantic analysis phase on the AST B-none Breaks: nothing, updates are internal and/or don't change existing features C-bug-report Category: bug report P-high Priority: should ship in the earliest possible release
Projects
None yet
Development

No branches or pull requests

1 participant