Skip to content

Commit

Permalink
raise error at correct location for wrong type
Browse files Browse the repository at this point in the history
  • Loading branch information
superlopuh committed Nov 29, 2024
1 parent c04c6dc commit ef290bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
23 changes: 23 additions & 0 deletions tests/filecheck/dialects/builtin/dense_array_invalid.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: xdsl-opt %s --parsing-diagnostics --split-input-file | filecheck %s --strict-whitespace --match-full-lines

// CHECK:"builtin.module" () {"test" = array<i32: "", 3>} ({
// CHECK-NEXT: ^^
// CHECK-NEXT: Expected integer literal
"builtin.module" () {"test" = array<i32: "", 3>} ({
})

// -----

// CHECK:"builtin.module" () {"test" = array<()->(): 2, 5, 2>} ({
// CHECK-NEXT: ^^^^^^
// CHECK-NEXT: dense array element type must be an integer or floating point type
"builtin.module" () {"test" = array<()->(): 2, 5, 2>} ({
})

// -----

// CHECK:"builtin.module" () {"test" = array<i8: 99999999, 255, 256>} ({
// CHECK-NEXT: ^^^^^^^^
// CHECK-NEXT: Integer value 99999999 is out of range for type i8 which supports values in the range [-128, 256)
"builtin.module" () {"test" = array<i8: 99999999, 255, 256>} ({
})

This file was deleted.

13 changes: 0 additions & 13 deletions tests/filecheck/dialects/builtin/dense_array_invalid_element.mlir

This file was deleted.

6 changes: 4 additions & 2 deletions xdsl/parser/attribute_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,14 @@ def _parse_typed_integer(

def _parse_builtin_densearray_attr(self, name: Span) -> DenseArrayBase | None:
self.parse_characters("<", " in dense array")
pos = self.pos
element_type = self.parse_attribute()

if not isinstance(element_type, IntegerType | AnyFloat):
raise ParseError(
name,
self.raise_error(
"dense array element type must be an integer or floating point type",
pos,
self.pos,
)

# Empty array
Expand Down

0 comments on commit ef290bc

Please sign in to comment.