summary refs log tree commit diff stats
path: root/compiler/astmsgs.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/astmsgs.nim')
-rw-r--r--compiler/astmsgs.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/astmsgs.nim b/compiler/astmsgs.nim
index d9105b761..a9027126a 100644
--- a/compiler/astmsgs.nim
+++ b/compiler/astmsgs.nim
@@ -26,3 +26,14 @@ proc addDeclaredLoc*(result: var string, conf: ConfigRef; typ: PType) =
 
 proc addDeclaredLocMaybe*(result: var string, conf: ConfigRef; typ: PType) =
   if optDeclaredLocs in conf.globalOptions: addDeclaredLoc(result, conf, typ)
+
+template quoteExpr*(a: string): untyped =
+  ## can be used for quoting expressions in error msgs.
+  "'" & a & "'"
+
+proc genFieldDefect*(conf: ConfigRef, field: string, disc: PSym): string =
+  let obj = disc.owner.name.s # `types.typeToString` might be better, eg for generics
+  result = "field '$#' is not accessible for type '$#'" % [field, obj]
+  if optDeclaredLocs in conf.globalOptions:
+    result.add " [discriminant declared in $#]" % toFileLineCol(conf, disc.info)
+  result.add " using '$# = " % disc.name.s