Skip to content

Commit 83868bc

Browse files
quark17sequencer
andauthored
Fix off-by-one column tracking for $-prefixed identifiers
The pattern `('$':x:cs)` consumes two characters (the '$' and the first identifier character 'x'), so the remaining input `cs` starts at column `c+2`, not `c+1`. This bug caused incorrect column positions to be reported for Verilog system tasks like $display, $finish, $time, etc. All subsequent tokens on the same line after a $-identifier would have their column numbers off by one. --------- Co-authored-by: Jiuyang Liu <liu@jiuyang.me>
1 parent 75c15be commit 83868bc

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

src/comp/Lex.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ lx lf f l c (ch:cs) | isDigit ch =
278278
in
279279
case span isDigit cs of
280280
(s', cs') -> lxFloat (ch:s') cs'
281-
lx lf f l c ('$':x:cs) | isIdChar x = spanId [] (c+1) cs
281+
lx lf f l c ('$':x:cs) | isIdChar x = spanId [] (c+2) cs
282282
where spanId r cn (y:cs) | (isIdChar y || y == '$') = spanId (y:r) (cn+1) cs
283283
spanId r cn cs' =
284284
let fs = mkFString ('$':x:reverse r)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package LexPos where
1+
package LexPos_NumLit where
22

33
x :: Integer
44
x = 5 + 9 + "foo"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package LexPos_Task where
2+
3+
-- Both 'f' and 'g' should have a type error at column 14
4+
-- as the reference to 'x' is at the same column in both
5+
6+
f :: Bool -> Action
7+
f x = $fwrite x
8+
9+
g :: Bool -> Action
10+
g x = dfwrite x
11+
12+
dfwrite :: File -> Action
13+
dfwrite x = $fwrite x

testsuite/bsc.syntax/bh/bh.exp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,26 @@ compile_pass_bug EmptyDo_Braces.bs
112112
# Confirm that the failure was due to an internal error
113113
find_regexp [make_bsc_output_name EmptyDo_Braces.bs] {Internal.*Error}
114114

115+
# -----
116+
# Test lexer positions
117+
118+
proc check_lex_pos { srcname linepos colpos {errtag T0020} {count 1}} {
119+
set str "Error: \"$srcname\", line $linepos, column $colpos: ($errtag)"
120+
find_n_strings [make_bsc_output_name $srcname] $str $count
121+
}
122+
115123
# Fix position after numeric literals with prefixes
116124
# (fixes Google issue #77395569)
117-
compile_fail LexPos.bs
118-
find_n_strings LexPos.bs.bsc-out {Error: "LexPos.bs", line 4, column 12: (T0020)} 1
119-
find_n_strings LexPos.bs.bsc-out {Error: "LexPos.bs", line 7, column 16: (T0020)} 1
125+
compile_fail LexPos_NumLit.bs
126+
check_lex_pos LexPos_NumLit.bs 4 12
127+
check_lex_pos LexPos_NumLit.bs 7 16
128+
129+
# Fix position after system task names (prefixed with dollarsign)
130+
compile_fail LexPos_Task.bs
131+
check_lex_pos LexPos_Task.bs 7 14
132+
check_lex_pos LexPos_Task.bs 10 14
133+
134+
# -----
120135

121136
# Allow _ in numeric literals
122137
# (fixes Google issue #67326190)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
checking package dependencies
22
compiling NotDisplayable.bs
3-
Error: "NotDisplayable.bs", line 6, column 14: (T0031)
3+
Error: "NotDisplayable.bs", line 6, column 15: (T0031)
44
The contexts for this expression could not be resolved because there are no
55
instances of the form:
66
Prelude.Bits NotDisplayable.Test a__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
checking package dependencies
22
compiling NotListDisplay.bs
3-
Error: "NotListDisplay.bs", line 6, column 17: (T0031)
3+
Error: "NotListDisplay.bs", line 6, column 18: (T0031)
44
The contexts for this expression could not be resolved because there are no
55
instances of the form:
66
Prelude.Bits (Prelude.List a) a__

0 commit comments

Comments
 (0)