fix type checking on certain bitwise operations

This commit is contained in:
gluax 2022-06-16 12:49:41 -07:00
parent ed9ca4d6d8
commit b656fd5347
13 changed files with 87 additions and 7 deletions

View File

@ -97,7 +97,7 @@ impl BinaryOperation {
sym::nand => Self::Nand,
sym::neq => Self::Neq,
sym::nor => Self::Nor,
sym::or => Self::Or,
sym::or => Self::BitwiseOr,
sym::pow => Self::Pow,
sym::pow_wrapped => Self::PowWrapped,
sym::shl => Self::Shl,

View File

@ -240,18 +240,18 @@ impl ParserContext<'_> {
let (mut args, _, span) = self.parse_expr_tuple()?;
let span = receiver.span() + span;
if let (true, Some(operator)) = (args.is_empty(), UnaryOperation::from_symbol(method.name)) {
if let (true, Some(op)) = (args.is_empty(), UnaryOperation::from_symbol(method.name)) {
// Found an unary operator and the argument list is empty.
Ok(Expression::Unary(UnaryExpression {
span,
op: operator,
op,
receiver: Box::new(receiver),
}))
} else if let (1, Some(operator)) = (args.len(), BinaryOperation::from_symbol(method.name)) {
} else if let (1, Some(op)) = (args.len(), BinaryOperation::from_symbol(method.name)) {
// Found a binary operator and the argument list contains a single argument.
Ok(Expression::Binary(BinaryExpression {
span,
op: operator,
op,
left: Box::new(receiver),
right: Box::new(args.swap_remove(0)),
}))

View File

@ -64,7 +64,7 @@ impl<'a> ExpressionVisitorDirector<'a> for Director<'a> {
fn visit_identifier(&mut self, input: &'a Identifier, expected: &Self::AdditionalInput) -> Option<Self::Output> {
if let VisitResult::VisitChildren = self.visitor.visit_identifier(input) {
return if let Some(var) = self.visitor.symbol_table.clone().lookup_variable(&input.name) {
Some(self.visitor.assert_expected_option(*var.type_, expected, input.span))
Some(self.visitor.assert_expected_option(*var.type_, expected, var.span))
} else {
self.visitor
.handler
@ -404,7 +404,7 @@ impl<'a> ExpressionVisitorDirector<'a> for Director<'a> {
let t1 = self.visit_expression(&input.left, destination);
// Assert right type is a magnitude (u8, u16, u32).
let t2 = self.visit_expression(&input.left, &None);
let t2 = self.visit_expression(&input.right, &None);
self.visitor.assert_magnitude_type(&t2, input.right.span());
return_incorrect_type(t1, t2, destination)

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: 93ebda249fd3f7ed822b3f8a630b12ee2465ae102ccba3ed821a1a70141c9697
initial_ast: 6b6adb1cc4b321352d34aa600b396c8b008ad77bc9d55b44bb629f84102b1df5
symbol_table: e0389ea48a5437967637260b107904a13a0def80df3f92f68a7893232ae1d99a

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: 1b57889f4cb20708dae67ca8d03a31ebb1bb64e698a5107d5cbe059676efca70
initial_ast: e43aebd8317b4fb9423fd63ebc33856c27b2555b73850cdf3da2d1aaa17aa1ca
symbol_table: da54e87473b2e414e01b8bf38f5fa6bbf77d557299fe79537d8546faff22fa05

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: 186316438d6152e5b5317511eaea7cb31bc7e361c6a9451a737f0f19a5b20854
initial_ast: ea2515217583ccf9d281fcae5e693b23398af0e0ba01624514666948cb0d5eb7
symbol_table: a353733198faed7b411c2eda3d359c1b00e6a5ef7c3790bd75639acaced6a43d

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: ec07a11fc89aaf21ce5b3f20e09a8930bbf68114a1e89862e6f8d7ed34e5fff8
initial_ast: 958ee92781093807db75e99508311dc26c78073c8e2ebe5fb1b0e12dbb73fc3e
symbol_table: 0c204022097d753b6f6d7f8eec9ae1f694f31460aca6879c44bfba2f8a1768c3

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: dc5f7cab0e9f520e9ea0fe03e2aca2c5bb93589dc8acf7a41b468381ac66b654
initial_ast: 6fa21c8806b845e410c20f85d21231a9e1df06e886bd777c35925715dedcfb60
symbol_table: 0b2ad811cdc7addac91c0f2845d19511860654c574be056b914e63401a1ca1f0

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: b6f2382216bfe7949ee0ed790a48e75981e34b55b43b52eac985b69cd4ec35e5
initial_ast: bf4d188a7ed9c47489ad5802b6fd05c13553a9fd4887f4c147afaf72b438ce22
symbol_table: 01cf24571bc1891336e94dab4d156b21b33dcf4e7dbb74cbb12f059cf4a442ae

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: 83cfba0c6e80aa0128aec20775c00686bfee37bb64b7c6d5f19214f4b8c85632
initial_ast: ea2c0e4d9699f5dd543cfa1b9e407bed5f28ea0e04977ce436959c9153ae577f
symbol_table: f6cda1bd2ed32fa4f2b4e5d7a825ff8e5ecc67170c280952a5e196316caa75d5

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: 4b30218dff8ce730a3955c1ba3a64ec83669d0751b72b9f9b89ceb4be579cd85
initial_ast: c7723d97feb8195aecc37884a750a34369bfd293c882a663129f7d81e4dfbab7
symbol_table: f74952bad4f239a84e310ae0aa3f5bfddf2697387cd0b361b7cafae68bd25745

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: bfd5a3bd075cda5c6ebcd6e2708e693f90813cf9103a06a680c12a217c479759
initial_ast: dbacb6680826a65077aa80b5e6110392e08e19b8c22b5b71371f771849261917
symbol_table: 14bda17d4237b8c0afa6b368d2785403283400c324010b97794745b6225d426f

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: 100e24373d817ea339956a770ab5baacdb9b31d7083b352b788814984e915541
initial_ast: 605a75fc99fb97463aad73c00cc1577fbf56856a076a77a05a0c4c3ae1762e93
symbol_table: 5b479875161904828d1f2e82199b9f8e9f389ba36911dcddcdec2dec0362d73f