Skip to content

Commit 17757f6

Browse files
committed
Fix function location in alias parsing
1 parent 89af78f commit 17757f6

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,16 @@ impl Parser {
204204
return Err(QccErrorKind::ExpectedFnName)?;
205205
}
206206
let function = self.lexer.identifier();
207+
let function_location = self.lexer.location.clone();
207208
self.lexer.consume(Token::Identifier)?;
208209

209210
if !self.lexer.is_token(Token::Semicolon) {
210211
return Err(QccErrorKind::ExpectedSemicolon)?;
211212
}
212213
self.lexer.consume(Token::Semicolon)?;
213214

214-
let alias = VarAST::new(alias, location.clone());
215-
let function = VarAST::new(function, location);
215+
let alias = VarAST::new(alias, location);
216+
let function = VarAST::new(function, function_location);
216217

217218
return Ok(AliasAST::new(alias, function));
218219
}
@@ -983,7 +984,7 @@ impl Parser {
983984
if !alias_resolved {
984985
seen_errors = true;
985986
let err = QccErrorKind::ExpectedFn;
986-
qcceprintln!("{} {} {}", err, to_alias, to_alias.location());
987+
qcceprintln!("{} '{}' {}", err, to_alias, to_alias.location());
987988
}
988989
}
989990

tests/test_alias_missing.ql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
alias H = Hadamard;
2+
3+
fn main(): !qbit {
4+
let q = 0q(0, 1);
5+
let x = H(q);
6+
7+
return x;
8+
}

tests/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ fn test_ast_gen() -> Result<(), Box<dyn std::error::Error>> {
336336
337337
");
338338

339+
// test!("tests/test_alias_missing.ql.ql.ql", "");
340+
339341
test!("examples/toss.ql",
340342
"|_ math // @math.ql:1:1
341343
|_ fn math$factorial (n: float64) : float64 // @math.ql:1:4

0 commit comments

Comments
 (0)