@@ -1212,14 +1212,22 @@ extends DeclarationMsg(OverrideErrorID), NoDisambiguation:
12121212
12131213class ForwardReferenceExtendsOverDefinition (value : Symbol , definition : Symbol )(using Context )
12141214extends ReferenceMsg (ForwardReferenceExtendsOverDefinitionID ) {
1215- def msg (using Context ) = i " ${definition.name} is a forward reference extending over the definition of ${value.name}"
1215+ extension (sym : Symbol ) def srcLine = sym.line + 1
1216+
1217+ def msg (using Context ) =
1218+ val ref =
1219+ if value != definition then i " ${definition.name} (defined on line ${definition.srcLine}) "
1220+ else i " ${definition.name}"
1221+ i " forward reference to ${ref} extends over the definition of ${value.name} (on line ${value.srcLine}) "
12161222
12171223 def explain (using Context ) =
12181224 i """ | ${definition.name} is used before you define it, and the definition of ${value.name}
12191225 |appears between that use and the definition of ${definition.name}.
12201226 |
1221- |Forward references are allowed only, if there are no value definitions between
1222- |the reference and the referred method definition.
1227+ |Forward references are allowed only if there are no value definitions between
1228+ |the reference and the definition that is referred to.
1229+ |Specifically, any statement between the reference and the definition
1230+ |cannot be a variable definition, and if it's a value definition, it must be lazy.
12231231 |
12241232 |Define ${definition.name} before it is used,
12251233 |or move the definition of ${value.name} so it does not appear between
0 commit comments