-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21150d5
commit f8b47db
Showing
19 changed files
with
254 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
crates/mun_codegen/src/snapshots/test__literal_types_file_ir.snap
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
crates/mun_codegen/src/snapshots/test__literal_types_group_ir.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use super::ExprValidator; | ||
use crate::diagnostics::{DiagnosticSink, LiteralOutOfRange}; | ||
use crate::ty::ResolveBitness; | ||
use crate::{ty_app, TypeCtor}; | ||
use crate::{Expr, HirDatabase, HirDisplay, Literal}; | ||
|
||
impl<'d, D: HirDatabase> ExprValidator<'d, D> { | ||
/// Iterates over all expressions to determine if one of the literals has a value that is out of | ||
/// range of its type. | ||
pub fn validate_literal_ranges(&self, sink: &mut DiagnosticSink) { | ||
self.body[self.body.body_expr].walk_child_exprs(move |expr_id| { | ||
let expr = &self.body[expr_id]; | ||
if let Expr::Literal(Literal::Int(lit)) = &expr { | ||
let ty = &self.infer[expr_id]; | ||
match ty { | ||
ty_app!(TypeCtor::Int(int_ty)) => { | ||
if lit.value > int_ty.resolve(&self.db.target_data_layout()).max() { | ||
let literal = self | ||
.body_source_map | ||
.expr_syntax(expr_id) | ||
.expect("could not retrieve expr from source map") | ||
.map(|expr_src| { | ||
expr_src | ||
.left() | ||
.expect("could not retrieve expr from ExprSource") | ||
.cast() | ||
.expect("could not cast expression to literal") | ||
}); | ||
sink.push(LiteralOutOfRange { | ||
literal, | ||
int_ty: *int_ty, | ||
}) | ||
} | ||
} | ||
_ => panic!( | ||
"expected int literal to have int ty while instead it is `{}`", | ||
ty.display(self.db) | ||
), | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.