Skip to content

Commit f89d9cc

Browse files
committed
Add testcases
1 parent f5f2996 commit f89d9cc

File tree

8 files changed

+54
-4
lines changed

8 files changed

+54
-4
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private sealed trait XSettings:
341341
val Xdumpclasses: Setting[String] = StringSetting(AdvancedSetting, "Xdump-classes", "dir", "Dump the generated bytecode to .class files (useful for reflective compilation that utilizes in-memory classloaders).", "")
342342
val XjarCompressionLevel: Setting[Int] = IntChoiceSetting(AdvancedSetting, "Xjar-compression-level", "compression level to use when writing jar files", Deflater.DEFAULT_COMPRESSION to Deflater.BEST_COMPRESSION, Deflater.DEFAULT_COMPRESSION)
343343
val XkindProjector: Setting[String] = ChoiceSetting(AdvancedSetting, "Xkind-projector", "[underscores, enable, disable]", "Allow `*` as type lambda placeholder to be compatible with kind projector. When invoked as -Xkind-projector:underscores will repurpose `_` to be a type parameter placeholder, this will disable usage of underscore as a wildcard.", List("disable", "", "underscores"), "disable", legacyArgs = true)
344-
val XmagicOffsetHeader: Setting[String] = StringSetting(AdvancedSetting, "Xmagic-offset-header", "header", "Specify the magic header comment that marks the start of the actual code in generated wrapper scripts.", "")
344+
val XmagicOffsetHeader: Setting[String] = StringSetting(AdvancedSetting, "Xmagic-offset-header", "header", "Specify the magic header comment that marks the start of the actual code in generated wrapper scripts. Example: -Xmagic-offset-header:///SOURCE_CODE_START", "")
345345

346346
/** Documentation related settings */
347347
val XdropComments: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xdrop-docs", "Drop documentation when scanning source files.", aliases = List("-Xdrop-comments"))

compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ trait MessageRendering {
4444
var maxLen = Int.MinValue
4545
def render(offsetAndLine: (Int, String)): String = {
4646
val (offset1, line) = offsetAndLine
47-
val magicOffset = WrappedSourceFile.locateMagicHeader(pos.source).getOrElse(0)
48-
println(i"magicOffset: $magicOffset")
49-
val lineNbr = (pos.source.offsetToLine(offset1) + 1 - magicOffset).toString
47+
var magicOffset = WrappedSourceFile.locateMagicHeader(pos.source).getOrElse(0)
48+
val lineId = pos.source.offsetToLine(offset1)
49+
if lineId < magicOffset then magicOffset = 0
50+
val lineNbr = (lineId + 1 - magicOffset).toString
5051
val prefix = String.format(s"%${offset - 2}s |", lineNbr)
5152
maxLen = math.max(maxLen, prefix.length)
5253
val lnum = hl(" " * math.max(0, maxLen - prefix.length - 1) + prefix)

tests/neg/magic-offset-header-a.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg/magic-offset-header-a.scala:6:19 ----------------------------------------------
2+
1 |def test1(): Int = "无穷" // error
3+
| ^^^^
4+
| Found: ("无穷" : String)
5+
| Required: Int
6+
|
7+
| longer explanation available when compiling with `-explain`

tests/neg/magic-offset-header-a.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//> using options -Xmagic-offset-header:///TEST_MARKER
2+
val t1 = 1
3+
val t2 = 2
4+
val t3 = 3
5+
///TEST_MARKER
6+
def test1(): Int = "无穷" // error

tests/neg/magic-offset-header-b.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E007] Type Mismatch Error: tests/neg/magic-offset-header-b.scala:3:13 ----------------------------------------------
2+
3 |def x: Int = true // error
3+
| ^^^^
4+
| Found: (true : Boolean)
5+
| Required: Int
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- [E007] Type Mismatch Error: tests/neg/magic-offset-header-b.scala:7:13 ----------------------------------------------
9+
2 |def y: Int = false // error
10+
| ^^^^^
11+
| Found: (false : Boolean)
12+
| Required: Int
13+
|
14+
| longer explanation available when compiling with `-explain`

tests/neg/magic-offset-header-b.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//> using options -Xmagic-offset-header:///TEST_MARKER
2+
3+
def x: Int = true // error
4+
5+
///TEST_MARKER
6+
7+
def y: Int = false // error

tests/neg/magic-offset-header-c.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg/magic-offset-header-c.scala:8:18 ----------------------------------------------
2+
3 | val x: String = 0 // error
3+
| ^
4+
| Found: (0 : Int)
5+
| Required: String
6+
|
7+
| longer explanation available when compiling with `-explain`

tests/neg/magic-offset-header-c.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -Xmagic-offset-header:///SOURCE_CODE_START_MARKER
2+
3+
val generatedCode = 123
4+
5+
///SOURCE_CODE_START_MARKER
6+
7+
def userCode =
8+
val x: String = 0 // error

0 commit comments

Comments
 (0)