gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Fresh objects not treated as fresh? #263

Open KimBruce opened 6 years ago

KimBruce commented 6 years ago

The following code should represent legal inheritance as e(j) tail-returns an object. However it crashes:

class mka(n: Number) {
    method m → String {"mka: calling m"}
    print "Creating mka"
}

method e(k: Number) {mka(k)}

class d(j: Number) {
    inherit e(j)
    method p → Number {
        print "calling p"
        m.size
    }
    print "creating d"
}

The error message is

Syntax error: unknown variable or method 'm'. This may be a spelling mistake or an attempt to access a variable in another scope.
    in "indirectInheritance" (line 12, column 9)

So, it doesn't complain about the inheritance, but it doesn't see the method m from the superclass. This is likely to be a symbol table issue in getting the inherited methods. Or I could be misunderstanding our rules for inheritance!

kjx commented 6 years ago

Hmm. Kernan here http://homepages.ecs.vuw.ac.nz/~mwh/js-kernan/entry/

says "InheritanceError: R2017: The method «e(_)» does not return an object that can be inherited."

I can't run Kernan itself easily as I'm still rebuilding a laptop - J

apblack commented 6 years ago

e(j) should be fresh, but minigrace doesn't recognize it as such.

Smallgrace does so recognize it, but crashed because it needs to disambiguate the request mka(_), which in general requires that inherited names be collected ... which is what we are doing. I just put in a patch to resolve the issue in this case, but I'm not sure how general it is — it will probably work so long as there is no cyclic inheritance.

I would like to port all of smallGrace's name resolution back into minigrace. I'm thinking about partially-automated Smalltalk to Grace method translation.

KimBruce commented 6 years ago

Here is another, slightly different, example we ran into today:

class numList → List⟦Number⟧ {
    inherit list⟦Number⟧.empty
}

print (numList.size)

Crashes with the error message:

ProgrammingError on line 2 of temp: attempting to inherit from 'empty' on the list class. This is not a fresh method.
  raised at numList at line 2 of temp
  requested from module initialization at line 5 of temp
  requested on line 5 of temp.
   1: class numList → List⟦Number⟧ {
   2:     inherit list⟦Number⟧.empty
   3: }

Yet, if you replace ".empty" by ".withall[]" it works fine, even though the code in the standard prelude is

   method empty -> List⟦T⟧ {
        withAll(emptySequence)
    }
apblack commented 5 years ago

@KimBruce's original example is in file _known-failing/transitive_freshnesstest.grace. The error message is

ProgrammingError: attempting to inherit from 'e(_)' on the "transitive_freshness_test" module (defined in module transitive_freshness_test, line 1). This is not a fresh method.
  raised at d(_) at line 9 of transitive_freshness_test
  requested from module initialization at line 17 of /Users/black/Development/mg/gracelang/minigrace/js/tests/known-failing/transitive_freshness_test.js

and is produced at runtime, because e(_) has not been compiled as a fresh method.