Skip to content

Commit d099250

Browse files
Merge pull request #10629 from dotty-staging/add-Position-constructor
Add constructor for reflect Position
2 parents bbdbdf2 + 1b63241 commit d099250

File tree

4 files changed

+7
-21
lines changed

4 files changed

+7
-21
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25232523
object Position extends PositionModule:
25242524
def ofMacroExpansion: dotc.util.SourcePosition =
25252525
MacroExpansion.position.getOrElse(dotc.util.SourcePosition(ctx.source, dotc.util.Spans.NoSpan))
2526+
def apply(sourceFile: SourceFile, start: Int, end: Int): Position =
2527+
dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end))
25262528
end Position
25272529

25282530
object PositionMethodsImpl extends PositionMethods:
@@ -2566,9 +2568,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25662568
def error(msg: String, pos: Position): Unit =
25672569
dotc.report.error(msg, pos)
25682570

2569-
def error(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
2570-
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
2571-
25722571
def throwError(msg: String): Nothing =
25732572
error(msg)
25742573
throw new scala.quoted.runtime.StopMacroExpansion
@@ -2581,10 +2580,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25812580
error(msg, pos)
25822581
throw new scala.quoted.runtime.StopMacroExpansion
25832582

2584-
def throwError(msg: String, sourceFile: SourceFile, start: Int, end: Int): Nothing =
2585-
error(msg, sourceFile, start, end)
2586-
throw new scala.quoted.runtime.StopMacroExpansion
2587-
25882583
def warning(msg: String): Unit =
25892584
dotc.report.warning(msg, Position.ofMacroExpansion)
25902585

@@ -2594,9 +2589,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25942589
def warning(msg: String, pos: Position): Unit =
25952590
dotc.report.warning(msg, pos)
25962591

2597-
def warning(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
2598-
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
2599-
26002592
end report
26012593

26022594
type Documentation = dotc.core.Comments.Comment

library/src/scala/quoted/Quotes.scala

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4067,6 +4067,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
40674067
trait PositionModule { this: Position.type =>
40684068
/** Position of the expansion site of the macro */
40694069
def ofMacroExpansion: Position
4070+
4071+
/** Create a new position in the source with the given range. The range must be contained in the file. */
4072+
def apply(sourceFile: SourceFile, start: Int, end: Int): Position
40704073
}
40714074

40724075
/** Makes extension methods on `Position` available without any imports */
@@ -4169,9 +4172,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
41694172
/** Report an error message at the given position */
41704173
def error(msg: String, pos: Position): Unit
41714174

4172-
/** Report an error at a specific range of a file. The positions must be contained in the file. */
4173-
def error(msg: String, source: SourceFile, start: Int, end: Int): Unit
4174-
41754175
/** Report an error at the position of the macro expansion and throws a StopMacroExpansion */
41764176
def throwError(msg: String): Nothing
41774177

@@ -4181,9 +4181,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
41814181
/** Report an error message at the given position and throws a StopMacroExpansion */
41824182
def throwError(msg: String, pos: Position): Nothing
41834183

4184-
/** Report an error at a specific range of a file and throws a StopMacroExpansion. The positions must be contained in the file. */
4185-
def throwError(msg: String, source: SourceFile, start: Int, end: Int): Nothing
4186-
41874184
/** Report a warning at the position of the macro expansion */
41884185
def warning(msg: String): Unit
41894186

@@ -4193,9 +4190,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
41934190
/** Report an warning message at the given position */
41944191
def warning(msg: String, pos: Position): Unit
41954192

4196-
/** Emits a warning at a specific range of a file. The positions must be contained in the file. */
4197-
def warning(msg: String, source: SourceFile, start: Int, end: Int): Unit
4198-
41994193
}
42004194

42014195

tests/neg-macros/tasty-macro-positions/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Macros {
88
import quotes.reflect._
99
val pos = Term.of(x).underlyingArgument.pos
1010
report.error("here is the the argument is " + Term.of(x).underlyingArgument.show, pos)
11-
report.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)
11+
report.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, Position(pos.sourceFile, pos.start + 5, pos.end + 5))
1212
'{}
1313
}
1414

0 commit comments

Comments
 (0)