Skip to content

Add constructor for reflect Position #10629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
object Position extends PositionModule:
def ofMacroExpansion: dotc.util.SourcePosition =
MacroExpansion.position.getOrElse(dotc.util.SourcePosition(ctx.source, dotc.util.Spans.NoSpan))
def apply(sourceFile: SourceFile, start: Int, end: Int): Position =
dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end))
end Position

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

def error(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))

def throwError(msg: String): Nothing =
error(msg)
throw new scala.quoted.runtime.StopMacroExpansion
Expand All @@ -2581,10 +2580,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
error(msg, pos)
throw new scala.quoted.runtime.StopMacroExpansion

def throwError(msg: String, sourceFile: SourceFile, start: Int, end: Int): Nothing =
error(msg, sourceFile, start, end)
throw new scala.quoted.runtime.StopMacroExpansion

def warning(msg: String): Unit =
dotc.report.warning(msg, Position.ofMacroExpansion)

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

def warning(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))

end report

type Documentation = dotc.core.Comments.Comment
Expand Down
12 changes: 3 additions & 9 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4067,6 +4067,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
trait PositionModule { this: Position.type =>
/** Position of the expansion site of the macro */
def ofMacroExpansion: Position

/** Create a new position in the source with the given range. The range must be contained in the file. */
def apply(sourceFile: SourceFile, start: Int, end: Int): Position
}

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

/** Report an error at a specific range of a file. The positions must be contained in the file. */
def error(msg: String, source: SourceFile, start: Int, end: Int): Unit

/** Report an error at the position of the macro expansion and throws a StopMacroExpansion */
def throwError(msg: String): Nothing

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

/** Report an error at a specific range of a file and throws a StopMacroExpansion. The positions must be contained in the file. */
def throwError(msg: String, source: SourceFile, start: Int, end: Int): Nothing

/** Report a warning at the position of the macro expansion */
def warning(msg: String): Unit

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

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

}


Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/tasty-macro-positions/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Macros {
import quotes.reflect._
val pos = Term.of(x).underlyingArgument.pos
report.error("here is the the argument is " + Term.of(x).underlyingArgument.show, pos)
report.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)
report.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, Position(pos.sourceFile, pos.start + 5, pos.end + 5))
'{}
}

Expand Down