bugKawa - Bugs: bug #47412, Can't use define in the...

 
 

bug #47412: Can't use define in the constructor of a subclass

Submitter:  None
Submitted:  Mon 14 Mar 2016 11:57:23 PM UTC
   
 
Category:  Code generation Severity:  3 - Normal
Item Group:  Compile-time exception Status:  Fixed
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 15 Mar 2016 06:48:06 AM UTC, comment #2: 

I checked in a fix for this.

I checked in a testcase based on your report.
Let me know who you are if you want to be credited in the testsuite./hangeLog file.

Per Bothner <bothner>
Group administrator
Tue 15 Mar 2016 01:08:06 AM UTC, comment #1: 

This one is difficult.
There are conflicting "rewrite" operations:

(1) A 'define' in a <block> (i.e. sequence of expressions and statements) is visible in the whole block, so the code is transformed into a let-form.

(2) Constructors are handled specially.  The code generator when handling a constructor looks for call to init on this or the super class.  However, if (1) happens, then it doesn't see the invoke-special, so it calls the default super constructor.  Then when we get to the invoke-special, we get an error since the object is already constructed.

A fix is for the logic in (2) to be smarter, so it can recognize constructor calls in a let.

Per Bothner <bothner>
Group administrator
Mon 14 Mar 2016 11:57:23 PM UTC, original submission:  

(define-simple-class A ()
((init) #!void)
)
(define-simple-class B (A)
((init)
(invoke-special A (this) '*init*)
(define i 0)
(display i)
)
)

Compiling this creates an exception:

Exception in thread "main" java.lang.Error: calling <init> on already-initialized object
        at gnu.bytecode.CodeAttr.emitInvokeMethod(CodeAttr.java:1549)
        at gnu.expr.PrimProcedure.compileInvoke(PrimProcedure.java:770)
        at gnu.expr.PrimProcedure.compile(PrimProcedure.java:751)
        at gnu.expr.PrimProcedure.compile(PrimProcedure.java:706)
        at gnu.expr.ApplyExp.inlineCompile(ApplyExp.java:683)
        at gnu.expr.ApplyExp.compile(ApplyExp.java:245)
        at gnu.expr.ApplyExp.compile(ApplyExp.java:191)
        at gnu.expr.Expression.compileWithPosition(Expression.java:143)
        at gnu.expr.Expression.compileWithPosition(Expression.java:126)
        at gnu.expr.BeginExp.compile(BeginExp.java:146)
        at gnu.expr.Expression.compileWithPosition(Expression.java:143)
        at gnu.expr.Expression.compileWithPosition(Expression.java:126)
        at gnu.expr.LetExp.compile(LetExp.java:196)
        at gnu.expr.Expression.compileWithPosition(Expression.java:143)
        at gnu.expr.LambdaExp.compileBody(LambdaExp.java:1689)
        at gnu.expr.ClassExp.compileMembers(ClassExp.java:561)
        at gnu.expr.LambdaExp.compileEnd(LambdaExp.java:613)
        at gnu.expr.Compilation.generateBytecode(Compilation.java:2300)
        at gnu.expr.Compilation.process(Compilation.java:2174)
        at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:302)
        at gnu.expr.ModuleExp.evalToClass(ModuleExp.java:73)
        at gnu.expr.ModuleExp.evalModule1(ModuleExp.java:246)
        at kawa.Shell.compileSource(Shell.java:557)
        at kawa.Shell.runFile(Shell.java:525)
        at kawa.Shell.runFileOrClass(Shell.java:438)
        at kawa.repl.processArgs(repl.java:678)
        at kawa.repl.main(repl.java:798)

If I just change it to a let then it works.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-04-08 bothner Open/ClosedOpen Closed
    2016-03-15 bothner StatusConfirmed Fixed
        Assigned toNone bothner
    2016-03-15 bothner StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code