gracelang / minigrace

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

Compiler crashes when empty method has a return-type from another module #324

Open IsaacOscar opened 4 years ago

IsaacOscar commented 4 years ago

I hade a strange compiler crash, this is the simplest code I could come up with that reproduced it:

In a file Foo.grace:

import "Bar" as Bar
method foo -> Bar.Foo { }

In a file Bar.grace:

type Foo = interface {}

Running mgc Foo.grace produces the following:

minigrace: Foo: 0.56 (+0.56): executing sub-compile of /root/Bar.grace
BoundsError: index 0 but list has size 0
  raised from list.at(_) at /root/minigrace/collections.grace:423
  requested from list.last at /root/minigrace/collections.grace:331
  requested from symbolTableVis.visitCall(_)up(_) at /root/minigrace/identifierresolution.grace:1050
  requested from symbolTableVis.visitMember(_)up(_) at /root/minigrace/identifierresolution.grace:1243
  requested from memberNode.new(_,_).accept(_)from(_) at /root/minigrace/ast.grace:1978
  requested from methodNode.new(_,_,_).accept(_)from(_) at /root/minigrace/ast.grace:1290
  requested from block.apply(_) at /root/minigrace/ast.grace:1617
  requested from block.apply at /root/minigrace/collections.grace:586
  requested from list.while(_)do(_) at intrinsic.grace:111
  requested from list.do(_) at /root/minigrace/collections.grace:582
  requested from moduleNode.body(_).accept(_)from(_) at /root/minigrace/ast.grace:1617
  requested from buildSymbolTableFor(_)ancestors(_) at /root/minigrace/identifierresolution.grace:1300
  requested from resolve(_) at /root/minigrace/identifierresolution.grace:1634
  requested from block.apply at /root/minigrace/compiler.grace:77
  requested from compileInputFile at /root/minigrace/compiler.grace:23
  requested from module initialization at /root/minigrace/compiler.grace:16
 422:         method at(n) { 423:             native "js" code ‹var idx = var_n._value; 424:                 var result = this._value[idx-1]
IsaacOscar commented 4 years ago

I fixed this by just adding an expression (such as done) within the foo method.