From bb03ca6097b267cd9c62cfff4f48d0920913479a Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sun, 11 Dec 2022 18:31:44 +0900 Subject: [PATCH] Fix Block::loc --- compiler/erg_compiler/hir.rs | 6 +++++- compiler/erg_parser/ast.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/erg_compiler/hir.rs b/compiler/erg_compiler/hir.rs index aa6be0e7..87afdaf3 100644 --- a/compiler/erg_compiler/hir.rs +++ b/compiler/erg_compiler/hir.rs @@ -1466,7 +1466,11 @@ impl_stream_for_wrapper!(Block, Expr); impl Locational for Block { fn loc(&self) -> Location { - Location::concat(self.0.first().unwrap(), self.0.last().unwrap()) + if self.0.is_empty() { + Location::Unknown + } else { + Location::concat(self.0.first().unwrap(), self.0.last().unwrap()) + } } } diff --git a/compiler/erg_parser/ast.rs b/compiler/erg_parser/ast.rs index 6b7fb9f7..99fcf5e8 100644 --- a/compiler/erg_parser/ast.rs +++ b/compiler/erg_parser/ast.rs @@ -1156,7 +1156,11 @@ impl_display_from_nested!(Block); impl Locational for Block { fn loc(&self) -> Location { - Location::concat(self.0.first().unwrap(), self.0.last().unwrap()) + if self.0.is_empty() { + Location::Unknown + } else { + Location::concat(self.0.first().unwrap(), self.0.last().unwrap()) + } } }