Skip to content

Commit 98751b3

Browse files
committed
pre-stage0 error name PR review edits
1 parent d81a8db commit 98751b3

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

src/Lean/Log.lean

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private def MessageData.appendDescriptionWidgetIfNamed (msg : MessageData) : Mes
9494
}
9595
-- Note: we do not generate corresponding message data for the widget because it pollutes
9696
-- console output
97-
msg.appendPreservingKind <| .ofWidget inst .nil
97+
msg.composePreservingKind <| .ofWidget inst .nil
9898
| none => msg
9999

100100
/--
@@ -137,6 +137,15 @@ protected def «logNamedErrorAt» (ref : Syntax) (name : Name) (msgData : Messag
137137
def logWarningAt [MonadOptions m] (ref : Syntax) (msgData : MessageData) : m Unit := do
138138
logAt ref msgData .warning
139139

140+
/--
141+
Log a named error warning using the given message data. The position is provided by `ref`.
142+
143+
Note: Use the macro `logNamedWarningAt`, which validates error names, instead of calling this function
144+
directly.
145+
-/
146+
protected def «logNamedWarningAt» (ref : Syntax) (name : Name) (msgData : MessageData) : m Unit :=
147+
logAt ref (msgData.tagWithErrorName name) MessageSeverity.warning
148+
140149
/-- Log a new information message using the given message data. The position is provided by `ref`. -/
141150
def logInfoAt (ref : Syntax) (msgData : MessageData) : m Unit :=
142151
logAt ref msgData MessageSeverity.information
@@ -164,6 +173,15 @@ protected def «logNamedError» (name : Name) (msgData : MessageData) : m Unit :
164173
def logWarning [MonadOptions m] (msgData : MessageData) : m Unit := do
165174
log msgData .warning
166175

176+
/--
177+
Log a named warning using the given message data. The position is provided by `getRef`.
178+
179+
Note: Use the macro `logNamedWarning`, which validates error names, instead of calling this function
180+
directly.
181+
-/
182+
protected def «logNamedWarning» (name : Name) (msgData : MessageData) : m Unit :=
183+
log (msgData.tagWithErrorName name) MessageSeverity.warning
184+
167185
/-- Log a new information message using the given message data. The position is provided by `getRef`. -/
168186
def logInfo (msgData : MessageData) : m Unit :=
169187
log msgData MessageSeverity.information

src/Lean/Message.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ def isTrace : MessageData → Bool
170170
| _ => false
171171

172172
/--
173-
`appendPreservingKind msg msg'` appends the contents of `msg'` to the end of `msg` but ensures that
173+
`composePreservingKind msg msg'` appends the contents of `msg'` to the end of `msg` but ensures that
174174
the resulting message preserves the kind (as given by `MessageData.kind`) of `msg`.
175175
-/
176-
def appendPreservingKind : MessageData → MessageData → MessageData
177-
| withContext ctx msg , msg' => withContext ctx (appendPreservingKind msg msg')
178-
| withNamingContext nc msg, msg' => withNamingContext nc (appendPreservingKind msg msg')
176+
def composePreservingKind : MessageData → MessageData → MessageData
177+
| withContext ctx msg , msg' => withContext ctx (composePreservingKind msg msg')
178+
| withNamingContext nc msg, msg' => withNamingContext nc (composePreservingKind msg msg')
179179
| tagged t msg , msg' => tagged t (compose msg msg')
180180
| msg , msg' => compose msg msg'
181181

src/Lean/Parser/Term.lean

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,12 +1119,29 @@ associated error explanation exists. The message may be passed as an interpolate
11191119
/--
11201120
Logs an error, tagging the message as a named error with the specified name and validating that an
11211121
associated error explanation exists. The error name must be followed by a `Syntax` at which the
1122-
error is to be thrown. The message is the final argument and may be passed as an interpolated string
1122+
error is to be logged. The message is the final argument and may be passed as an interpolated string
11231123
or a `MessageData` term.
11241124
-/
11251125
@[builtin_term_parser] def logNamedErrorAtMacro := leading_parser
11261126
"logNamedErrorAt " >> termParser maxPrec >> ppSpace >> identWithPartialTrailingDot >> ppSpace >> (interpolatedStr termParser <|> termParser maxPrec)
11271127

1128+
/--
1129+
Logs a warning, tagging the message as a named diagnostic with the specified name and validating
1130+
that an associated error explanation exists. The message may be passed as an interpolated string or
1131+
a `MessageData` term. The result of `getRef` is used as position information.
1132+
-/
1133+
@[builtin_term_parser] def logNamedWarningMacro := leading_parser
1134+
"logNamedWarning " >> identWithPartialTrailingDot >> ppSpace >> (interpolatedStr termParser <|> termParser maxPrec)
1135+
1136+
/--
1137+
Logs a warning, tagging the message as a named diagnostic with the specified name and validating
1138+
that an associated error explanation exists. The error name must be followed by a `Syntax` at which
1139+
the warning is to be logged. The message is the final argument and may be passed as an interpolated
1140+
string or a `MessageData` term.
1141+
-/
1142+
@[builtin_term_parser] def logNamedWarningAtMacro := leading_parser
1143+
"logNamedWarningAt " >> termParser maxPrec >> ppSpace >> identWithPartialTrailingDot >> ppSpace >> (interpolatedStr termParser <|> termParser maxPrec)
1144+
11281145
end Term
11291146

11301147
@[builtin_term_parser default+1] def Tactic.quot : Parser := leading_parser

0 commit comments

Comments
 (0)