Skip to content

Commit

Permalink
astgen: disallow ??type
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Jul 3, 2024
1 parent 5876341 commit 8ffc16b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bsc/astgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,13 @@ def user_type_decl(self, *names):
return BasicType(left, left.pos)

def option_type_decl(self, *nodes):
return OptionType(nodes[1], self.mkpos(nodes[0]))
inner_type = nodes[1]
pos = self.mkpos(nodes[0])
if isinstance(inner_type, OptionType):
report.error(
"cannot declare an option type using another option type", pos
)
return OptionType(inner_type, pos)

def array_type_decl(self, *nodes):
has_size = not isinstance(nodes[1], Token)
Expand Down
3 changes: 3 additions & 0 deletions tests/invalid_code/invalid_option_type.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() ??int {
return 0;
}
1 change: 1 addition & 0 deletions tests/invalid_code/invalid_option_type.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/invalid_code/invalid_option_type.bs:1:11: error: cannot declare an option type using another option type

0 comments on commit 8ffc16b

Please sign in to comment.