Skip to content

Commit 5b238f5

Browse files
committed
Add constructor for reflect Position
Also remove method from reporting recived a custom position.
1 parent 04737b5 commit 5b238f5

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25162516
object Position extends PositionModule:
25172517
def ofMacroExpansion: dotc.util.SourcePosition =
25182518
MacroExpansion.position.getOrElse(dotc.util.SourcePosition(ctx.source, dotc.util.Spans.NoSpan))
2519+
def apply(sourceFile: SourceFile, start: Int, end: Int): Position =
2520+
dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end))
25192521
end Position
25202522

25212523
object PositionMethodsImpl extends PositionMethods:
@@ -2559,9 +2561,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25592561
def error(msg: String, pos: Position): Unit =
25602562
dotc.report.error(msg, pos)
25612563

2562-
def error(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
2563-
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
2564-
25652564
def throwError(msg: String): Nothing =
25662565
error(msg)
25672566
throw new scala.quoted.runtime.StopMacroExpansion
@@ -2574,10 +2573,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25742573
error(msg, pos)
25752574
throw new scala.quoted.runtime.StopMacroExpansion
25762575

2577-
def throwError(msg: String, sourceFile: SourceFile, start: Int, end: Int): Nothing =
2578-
error(msg, sourceFile, start, end)
2579-
throw new scala.quoted.runtime.StopMacroExpansion
2580-
25812576
def warning(msg: String): Unit =
25822577
dotc.report.warning(msg, Position.ofMacroExpansion)
25832578

@@ -2587,9 +2582,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25872582
def warning(msg: String, pos: Position): Unit =
25882583
dotc.report.warning(msg, pos)
25892584

2590-
def warning(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
2591-
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
2592-
25932585
end report
25942586

25952587
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
@@ -4048,6 +4048,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
40484048
trait PositionModule { this: Position.type =>
40494049
/** Position of the expansion site of the macro */
40504050
def ofMacroExpansion: Position
4051+
4052+
/** Create a new position in the source with the given range. The range must be contained in the file. */
4053+
def apply(sourceFile: SourceFile, start: Int, end: Int): Position
40514054
}
40524055

40534056
/** Makes extension methods on `Position` available without any imports */
@@ -4150,9 +4153,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
41504153
/** Report an error message at the given position */
41514154
def error(msg: String, pos: Position): Unit
41524155

4153-
/** Report an error at a specific range of a file. The positions must be contained in the file. */
4154-
def error(msg: String, source: SourceFile, start: Int, end: Int): Unit
4155-
41564156
/** Report an error at the position of the macro expansion and throws a StopMacroExpansion */
41574157
def throwError(msg: String): Nothing
41584158

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

4165-
/** Report an error at a specific range of a file and throws a StopMacroExpansion. The positions must be contained in the file. */
4166-
def throwError(msg: String, source: SourceFile, start: Int, end: Int): Nothing
4167-
41684165
/** Report a warning at the position of the macro expansion */
41694166
def warning(msg: String): Unit
41704167

@@ -4174,9 +4171,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
41744171
/** Report an warning message at the given position */
41754172
def warning(msg: String, pos: Position): Unit
41764173

4177-
/** Emits a warning at a specific range of a file. The positions must be contained in the file. */
4178-
def warning(msg: String, source: SourceFile, start: Int, end: Int): Unit
4179-
41804174
}
41814175

41824176

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)