Skip to content

Commit 6783853

Browse files
authored
Merge pull request #15209 from dos65/fix_positions_for_tab_indented
Fix `SourceFile.column` method.
2 parents 324516b + 5cb1abf commit 6783853

File tree

6 files changed

+63
-33
lines changed

6 files changed

+63
-33
lines changed

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
7575

7676
def maybeIncomplete: Boolean = _maybeInComplete
7777

78-
/** Tab increment; can be overridden */
79-
def tabInc: Int = 8
80-
8178
override def name: String = file.name
8279
override def path: String = file.path
8380
override def jfile: Optional[JFile] = Optional.ofNullable(file.file)
@@ -197,12 +194,7 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
197194
/** The column corresponding to `offset`, starting at 0 */
198195
def column(offset: Int): Int = {
199196
var idx = startOfLine(offset)
200-
var col = 0
201-
while (idx != offset) {
202-
col += (if (idx < content().length && content()(idx) == '\t') (tabInc - col) % tabInc else 1)
203-
idx += 1
204-
}
205-
col
197+
offset - idx
206198
}
207199

208200
/** The padding of the column corresponding to `offset`, includes tabs */

tests/neg/doubleDefinition.check

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:14:4 ----------------------------------------------------------
1+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:14:5 ----------------------------------------------------------
22
14 | def foo(x: List[B]): Function1[B, B] = ??? // error: same jvm signature
33
| ^
44
| Double definition:
@@ -8,38 +8,38 @@
88
|
99
| Consider adding a @targetName annotation to one of the conflicting definitions
1010
| for disambiguation.
11-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:21:4 ----------------------------------------------------------
11+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:21:5 ----------------------------------------------------------
1212
21 | def foo(x: List[A]): Function2[B, B, B] = ??? // error
1313
| ^
1414
| Double definition:
1515
| def foo(x: List[A]): A => A in class Test3 at line 20 and
1616
| def foo(x: List[A]): (B, B) => B in class Test3 at line 21
1717
| have matching parameter types.
18-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:26:4 ----------------------------------------------------------
18+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:26:5 ----------------------------------------------------------
1919
26 | def foo = 2 // error
2020
| ^
2121
| Double definition:
2222
| val foo: Int in class Test4 at line 25 and
2323
| def foo: Int in class Test4 at line 26
24-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:31:4 ----------------------------------------------------------
24+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:31:5 ----------------------------------------------------------
2525
31 | val foo = 1 // error
2626
| ^
2727
| Double definition:
2828
| def foo: Int in class Test4b at line 30 and
2929
| val foo: Int in class Test4b at line 31
30-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:36:4 ----------------------------------------------------------
30+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:36:5 ----------------------------------------------------------
3131
36 | var foo = 1 // error
3232
| ^
3333
| Double definition:
3434
| def foo: Int in class Test4c at line 35 and
3535
| var foo: Int in class Test4c at line 36
36-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:41:4 ----------------------------------------------------------
36+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:41:5 ----------------------------------------------------------
3737
41 | def foo = 2 // error
3838
| ^
3939
| Double definition:
4040
| var foo: Int in class Test4d at line 40 and
4141
| def foo: Int in class Test4d at line 41
42-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:55:4 ----------------------------------------------------------
42+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:55:5 ----------------------------------------------------------
4343
55 | def foo(x: List[B]): Function1[B, B] = ??? // error: same jvm signature
4444
| ^
4545
| Double definition:
@@ -49,80 +49,80 @@
4949
|
5050
| Consider adding a @targetName annotation to one of the conflicting definitions
5151
| for disambiguation.
52-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:62:4 ----------------------------------------------------------
52+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:62:5 ----------------------------------------------------------
5353
62 | def foo(x: List[A]): Function2[B, B, B] = ??? // error
5454
| ^
5555
| Double definition:
5656
| def foo(x: List[A]): A => A in trait Test7 at line 61 and
5757
| def foo(x: List[A]): (B, B) => B in trait Test7 at line 62
5858
| have matching parameter types.
59-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:67:4 ----------------------------------------------------------
59+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:67:5 ----------------------------------------------------------
6060
67 | def foo = 2 // error
6161
| ^
6262
| Double definition:
6363
| val foo: Int in class Test8 at line 66 and
6464
| def foo: Int in class Test8 at line 67
65-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:72:4 ----------------------------------------------------------
65+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:72:5 ----------------------------------------------------------
6666
72 | val foo = 1 // error
6767
| ^
6868
| Double definition:
6969
| def foo: Int in class Test8b at line 71 and
7070
| val foo: Int in class Test8b at line 72
71-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:77:4 ----------------------------------------------------------
71+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:77:5 ----------------------------------------------------------
7272
77 | var foo = 1 // error
7373
| ^
7474
| Double definition:
7575
| def foo: Int in class Test8c at line 76 and
7676
| var foo: Int in class Test8c at line 77
77-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:82:4 ----------------------------------------------------------
77+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:82:5 ----------------------------------------------------------
7878
82 | def foo = 2 // error
7979
| ^
8080
| Double definition:
8181
| var foo: Int in class Test8d at line 81 and
8282
| def foo: Int in class Test8d at line 82
83-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:88:4 ----------------------------------------------------------
83+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:88:5 ----------------------------------------------------------
8484
88 | def foo: String // error
8585
| ^
8686
| Double definition:
8787
| val foo: Int in class Test9 at line 87 and
8888
| def foo: String in class Test9 at line 88
89-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:92:4 ----------------------------------------------------------
89+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:92:5 ----------------------------------------------------------
9090
92 | def foo: Int // error
9191
| ^
9292
| Double definition:
9393
| val foo: Int in class Test10 at line 91 and
9494
| def foo: Int in class Test10 at line 92
95-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:96:4 ----------------------------------------------------------
95+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:96:5 ----------------------------------------------------------
9696
96 | def foo: String // error
9797
| ^
9898
| Double definition:
9999
| val foo: Int in class Test11 at line 95 and
100100
| def foo: String in class Test11 at line 96
101-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:100:4 ---------------------------------------------------------
101+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:100:5 ---------------------------------------------------------
102102
100 | def foo: Int // error
103103
| ^
104104
| Double definition:
105105
| val foo: Int in class Test12 at line 99 and
106106
| def foo: Int in class Test12 at line 100
107-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:104:4 ---------------------------------------------------------
107+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:104:5 ---------------------------------------------------------
108108
104 | def foo: String // error
109109
| ^
110110
| Double definition:
111111
| var foo: Int in class Test13 at line 103 and
112112
| def foo: String in class Test13 at line 104
113-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:108:4 ---------------------------------------------------------
113+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:108:5 ---------------------------------------------------------
114114
108 | def foo: Int // error
115115
| ^
116116
| Double definition:
117117
| var foo: Int in class Test14 at line 107 and
118118
| def foo: Int in class Test14 at line 108
119-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:112:4 ---------------------------------------------------------
119+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:112:5 ---------------------------------------------------------
120120
112 | def foo: String // error
121121
| ^
122122
| Double definition:
123123
| var foo: Int in class Test15 at line 111 and
124124
| def foo: String in class Test15 at line 112
125-
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:116:4 ---------------------------------------------------------
125+
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:116:5 ---------------------------------------------------------
126126
116 | def foo: Int // error
127127
| ^
128128
| Double definition:

tests/neg/spaces-vs-tabs.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
| Incompatible combinations of tabs and spaces in indentation prefixes.
55
| Previous indent : 2 tabs
66
| Latest indent : 4 spaces
7-
-- Error: tests/neg/spaces-vs-tabs.scala:6:8 ---------------------------------------------------------------------------
7+
-- Error: tests/neg/spaces-vs-tabs.scala:6:3 ---------------------------------------------------------------------------
88
6 | println(3) // error
99
| ^
1010
| Incompatible combinations of tabs and spaces in indentation prefixes.
1111
| Previous indent : 2 tabs
1212
| Latest indent : 2 spaces, 1 tab
13-
-- Error: tests/neg/spaces-vs-tabs.scala:7:2 ---------------------------------------------------------------------------
13+
-- Error: tests/neg/spaces-vs-tabs.scala:7:3 ---------------------------------------------------------------------------
1414
7 | println(4) // error
1515
| ^
1616
| Incompatible combinations of tabs and spaces in indentation prefixes.
@@ -22,13 +22,13 @@
2222
| Incompatible combinations of tabs and spaces in indentation prefixes.
2323
| Previous indent : 2 tabs
2424
| Latest indent : 1 space
25-
-- Error: tests/neg/spaces-vs-tabs.scala:14:2 --------------------------------------------------------------------------
25+
-- Error: tests/neg/spaces-vs-tabs.scala:14:3 --------------------------------------------------------------------------
2626
14 | else 2 // error
2727
| ^
2828
| The start of this line does not match any of the previous indentation widths.
2929
| Indentation width of current line : 1 tab, 2 spaces
3030
| This falls between previous widths: 1 tab and 1 tab, 4 spaces
31-
-- [E129] Potential Issue Warning: tests/neg/spaces-vs-tabs.scala:13:6 -------------------------------------------------
31+
-- [E129] Potential Issue Warning: tests/neg/spaces-vs-tabs.scala:13:7 -------------------------------------------------
3232
13 | 1
3333
| ^
3434
| A pure expression does nothing in statement position; you may be omitting necessary parentheses
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package example
2+
3+
val a/*<-example::Tabs$package.a.*/ =
4+
List/*->scala::package.List.*/(1,2,3)
5+
.map/*->scala::collection::immutable::List#map().*/(_ +/*->scala::Int#`+`(+4).*/ 1)

tests/semanticdb/expect/Tabs.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package example
2+
3+
val a =
4+
List(1,2,3)
5+
.map(_ + 1)

tests/semanticdb/metac.expect

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,34 @@ Synthetics:
33933393
[55:6..55:12):foo(x) => *(x)
33943394
[58:6..58:12):foo(0) => *(given_Int)
33953395

3396+
expect/Tabs.scala
3397+
-----------------
3398+
3399+
Summary:
3400+
Schema => SemanticDB v4
3401+
Uri => Tabs.scala
3402+
Text => empty
3403+
Language => Scala
3404+
Symbols => 2 entries
3405+
Occurrences => 5 entries
3406+
Synthetics => 2 entries
3407+
3408+
Symbols:
3409+
example/Tabs$package. => final package object example extends Object { self: example.type => +2 decls }
3410+
example/Tabs$package.a. => val method a List[Int]
3411+
3412+
Occurrences:
3413+
[0:8..0:15): example <- example/
3414+
[2:4..2:5): a <- example/Tabs$package.a.
3415+
[3:1..3:5): List -> scala/package.List.
3416+
[4:3..4:6): map -> scala/collection/immutable/List#map().
3417+
[4:9..4:10): + -> scala/Int#`+`(+4).
3418+
3419+
Synthetics:
3420+
[3:1..4:6):List(1,2,3)
3421+
.map => *[Int]
3422+
[3:1..3:5):List => *.apply[Int]
3423+
33963424
expect/Traits.scala
33973425
-------------------
33983426

0 commit comments

Comments
 (0)