@@ -1261,8 +1261,11 @@ inductive LValResolution where
12611261 The `baseName` is the base name of the type to search for in the parameter list. -/
12621262 | localRec (baseName : Name) (fvar : Expr)
12631263
1264+ private def mkLValError (e : Expr) (eType : Expr) (msg : MessageData) : MessageData :=
1265+ m!"{msg}{indentExpr e}\n has type{indentExpr eType}"
1266+
12641267private def throwLValErrorAt (ref : Syntax) (e : Expr) (eType : Expr) (msg : MessageData) : TermElabM α :=
1265- throwErrorAt ref "{msg}{indentExpr e} \n has type{indentExpr eType}"
1268+ throwErrorAt ref (mkLValError e eType msg)
12661269
12671270private def throwLValError (e : Expr) (eType : Expr) (msg : MessageData) : TermElabM α := do
12681271 throwLValErrorAt (← getRef) e eType msg
@@ -1329,9 +1332,13 @@ where
13291332 | some (_, p2) => prodArity p2 + 1
13301333
13311334private def resolveLValAux (e : Expr) (eType : Expr) (lval : LVal) : TermElabM LValResolution := do
1332- let throwInvalidFieldAt {α : Type } (ref : Syntax) (fieldName : String) (fullName : Name) : TermElabM α := do
1333- throwLValErrorAt ref e eType <| ← mkUnknownIdentifierMessage (declHint := fullName)
1334- m!"Invalid field `{fieldName}`: The environment does not contain `{fullName}`"
1335+ let throwInvalidFieldAt {α : Type } (ref : Syntax) (fieldName : String) (fullName : Name)
1336+ (declHint := Name.anonymous) : TermElabM α := do
1337+ throwErrorAt ref (←
1338+ -- ordering: put decl hint, if any, last
1339+ mkUnknownIdentifierMessage (declHint := declHint)
1340+ (mkLValError e eType
1341+ m!"Invalid field `{fieldName}`: The environment does not contain `{fullName}`" ))
13351342 if eType.isForall then
13361343 match lval with
13371344 | LVal.fieldName _ fieldName suffix? fullRef =>
@@ -1397,6 +1404,9 @@ private def resolveLValAux (e : Expr) (eType : Expr) (lval : LVal) : TermElabM L
13971404 if let some (baseStructName, fullName) ← findMethod? structName (.mkSimple fieldName) then
13981405 return LValResolution.const baseStructName structName fullName
13991406 throwInvalidFieldAt fullRef fieldName fullName
1407+ -- Suggest a potential unreachable private name as hint. This does not cover structure
1408+ -- inheritance, nor `import all`.
1409+ (declHint := (mkPrivateName env structName).mkStr fieldName)
14001410 | none, LVal.fieldName _ _ (some suffix) fullRef =>
14011411 -- This may be a function constant whose implicit arguments have already been filled in:
14021412 let c := e.getAppFn
0 commit comments