carp-lang / Carp

A statically typed lisp, without a GC, for real-time applications.
Apache License 2.0
5.47k stars 173 forks source link

interface resolution fails to respect overrides #1414

Closed scolsen closed 2 years ago

scolsen commented 2 years ago

minimal rerpoducible example:

(definterface FOO a)

(defmodule Foo
  (register FOO Int "INT_MAX")
  (implements FOO FOO)
)

(defmodule Rando
    (defn rand []
      FOO)
)

(defn main []
  (the Int (Rando.rand))
)

FOO will be resolved to the C name Foo_FOO (the carp symbol as C) instead of the correct INT_MAX .

I think this is because the current interface code "fakes" qualification on implementation paths instead of properly qualifying their symbols (override replacement occurs in qualification, on a related note, this should probably happen in emit not in qualification).

scolsen commented 2 years ago

blocks #1412

scolsen commented 2 years ago

the issue lies in concretize. it currently overwrites the lookup mode of symbols to "AFunction" when resolving interfaces -- however, for registered externals with overrides, the override text eventually used by Emit.hs is contained in the symbols lookup mode, so we need to preserve this!