Error 'unbound identifier' while read-syntax on expand phase

Hi! I have a problem which I could not wrap my head around...

There is an error 'unbound identifier' in transform stage when I try to load some configuration with 'read-syntax'. This works at runtime stage.

What I try to do is get the syntax object for the symbols in the file, I need it to use srcloc (I am writing a small DSL for running tasks).
Here is a minimal code which shows the problem sample-loader.rkt · GitHub

sample-loader.rkt

#lang racket
(require (for-syntax racket))

(define-syntax (sample stx)
  (syntax-case stx (file)
    ((_ (file path))
     (let ((file (syntax->datum #'path)))
       (call-with-input-string
        (file->string file)
        (lambda (port) (read-syntax file port)))))))

(sample (file "./sample.rkt"))

; ./sample.rkt::2: say-hello: unbound identifier;
;  also, no #%app syntax transformer is bound
;   at: say-hello
;   in: (say-hello)
;   Source locations:
;   ./sample.rkt:1:0

sample.rkt

(say-hello)

The question is: how this could be fixed?
Thank you.

1 Like

Whoopsie.
I have rewrite my sample... looks like as my mistake.
This error is still reproducible for me in my personal project, but not in this sample:

#lang racket
(require (for-syntax racket))

(define-syntax (sample-quote stx)
  (syntax-case stx ()
    ((_ xs ...) (syntax '(xs ...)))))

(define-syntax (sample stx)
  (syntax-case stx (file)
    ((_ (file path))
     (with-syntax ((expression (let ((file (syntax->datum #'path)))
                                 (call-with-input-string
                                  (file->string file)
                                  (lambda (port) (read-syntax file port))))))
       (syntax (sample-quote expression))))))

(sample (file "./sample.rkt"))

; '((say-hello)) 

So, I think it solved.