summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semtempl.nim3
-rw-r--r--tests/stylecheck/taccept.nim17
-rw-r--r--tests/stylecheck/treject.nim17
3 files changed, 36 insertions, 1 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index 49ce55a64..b921fda2c 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -270,7 +270,8 @@ proc semTemplSymbol(c: PContext, n: PNode, s: PSym; isField: bool): PNode =
     # Issue #12832
     when defined(nimsuggest):
       suggestSym(c.graph, n.info, s, c.graph.usageSym, false)
-    if {optStyleHint, optStyleError} * c.config.globalOptions != {}:
+    # field access (dot expr) will be handled by builtinFieldAccess
+    if not isField and {optStyleHint, optStyleError} * c.config.globalOptions != {}:
       styleCheckUse(c.config, n.info, s)
 
 proc semRoutineInTemplName(c: var TemplCtx, n: PNode): PNode =
diff --git a/tests/stylecheck/taccept.nim b/tests/stylecheck/taccept.nim
new file mode 100644
index 000000000..6fb55f835
--- /dev/null
+++ b/tests/stylecheck/taccept.nim
@@ -0,0 +1,17 @@
+discard """
+  matrix: "--styleCheck:error --styleCheck:usages"
+"""
+
+import asyncdispatch
+
+type
+  Name = object
+    id: int
+
+template hello =
+  var iD = "string"
+  var name: Name
+  doAssert name.id == 0
+  doAssert iD == "string"
+
+hello()
diff --git a/tests/stylecheck/treject.nim b/tests/stylecheck/treject.nim
new file mode 100644
index 000000000..b9d97a58d
--- /dev/null
+++ b/tests/stylecheck/treject.nim
@@ -0,0 +1,17 @@
+discard """
+  action: reject
+  nimout: '''treject.nim(14, 13) Error: 'iD' should be: 'id' [field declared in treject.nim(9, 5)]'''
+  matrix: "--styleCheck:error --styleCheck:usages"
+"""
+
+type
+  Name = object
+    id: int
+
+template hello =
+  var iD = "string"
+  var name: Name
+  echo name.iD
+  echo iD
+
+hello()
\ No newline at end of file