From 6f0d247e8331c9e36d97430c9619a8d4b5c59f66 Mon Sep 17 00:00:00 2001 From: Bogdan Popa Date: Wed, 6 Mar 2024 08:30:09 +0200 Subject: [PATCH] lint: track define-like identifier usages --- lint.rkt | 10 ++++++---- tests/lint/define-syntax-rule.rkt | 11 +++++++++++ tests/lint/define-syntax-rule.rkt.out | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/lint/define-syntax-rule.rkt create mode 100644 tests/lint/define-syntax-rule.rkt.out diff --git a/lint.rkt b/lint.rkt index 3b5ca6b..7c98bc4 100644 --- a/lint.rkt +++ b/lint.rkt @@ -716,17 +716,19 @@ #:do [(pop-scope!) (pop-scope!)]) - (pattern (_:define-like + (pattern (define-id:define-like name:define-identifier ~! - e:expression ...+)) + e:expression ...+) + #:do [(track-binding-usage! (format-binding "~a" #'define-id))]) - (pattern (_:define-like + (pattern (define-id:define-like hdr:function-header ~! (~do (push-scope!)) e:expression ...+) - #:do [(for ([_ (in-range (add1 (attribute hdr.depth)))]) + #:do [(track-binding-usage! (format-binding "~a" #'define-id)) + (for ([_ (in-range (add1 (attribute hdr.depth)))]) (pop-scope!))])) (define-syntax-class root-module-path diff --git a/tests/lint/define-syntax-rule.rkt b/tests/lint/define-syntax-rule.rkt new file mode 100644 index 0000000..85427f0 --- /dev/null +++ b/tests/lint/define-syntax-rule.rkt @@ -0,0 +1,11 @@ +#lang racket/base + +(require (for-syntax racket/base)) + +(define-syntax-rule (define-keywords id ...) + (begin + (provide id ...) + (define-syntax (id stx) + (raise-syntax-error 'id "not allowed outside special form" stx)) ...)) + +(define-keywords foo bar baz) diff --git a/tests/lint/define-syntax-rule.rkt.out b/tests/lint/define-syntax-rule.rkt.out new file mode 100644 index 0000000..1ee1f9b --- /dev/null +++ b/tests/lint/define-syntax-rule.rkt.out @@ -0,0 +1 @@ +/define-syntax-rule.rkt:11:18:warning:identifier 'foo' is never used