Question: Declaring type to be a Class defined and included inside the same or child library

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Question: Declaring type to be a Class defined and included inside the same or child library

spellcard199
Hello. I'm writing here because I'm not sure if this Kawa behavior is the expected one or it's an issue.

I have 3 files:
- 1 file with the library definition
- 2 files, each containing one class

One of the 2 classes has a field whose type is the class defined in the other file.

Minimal Example (I could make it in a single file, but I'm putting the emphasis on the `include`, since `load` works instead)

Class1.scm

  (define-simple-class Class1 ())

Class2.scm

  (define-simple-class Class2 ()
    (x ::<Class1>)
    ((*init*)
     (set! x (Class1))))

foobar.sld

  (define-library (xxx)
    (import (kawa base))
    (include "Class1.scm")
    (include "Class2.scm"))

When I do... :

  kawa -f foobar.sld

... I get an exception:

  Class2.scm:4:4: caught exception in inliner for #<procedure gnu.kawa.functions.AppendValues> - java.lang.RuntimeException: no such class: Class1

I can avoid the exception:
- removing the type declaration
- using `(load "Class2.scm")` instead of `(include "Class2.scm")` in foobar.sld

At the moment I'm using the second option and it works fine for me.

The thing that made me ask instead of assuming this is the expected behavior is that it's ok to use Class1 as a superclass of Class2, so Class2 does "see" Class1. For example, this does not raise an exception:

  (define-simple-class Class2 (Class1)
    (x)
    ((*init*)
     (set! x (Class1))))

So my question is: am I doing it the wrong way or is it a Kawa issue? Should I open an issue in the Kawa repo?