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

 
 

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

Submitted by:  None
Submitted on:  Mon 14 Mar 2016 11:57:23 PM UTC  
 
Category: Code generationSeverity: 3 - Normal
Item Group: Compile-time exceptionStatus: Fixed
Privacy: PublicAssigned to: Per Bothner <bothner>
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project AdministratorIn charge of this item.
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>
Project AdministratorIn charge of this item.
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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 08 Apr 2016 05:19:41 PM UTCbothnerOpen/ClosedOpen=>Closed
    Tue 15 Mar 2016 06:48:06 AM UTCbothnerStatusConfirmed=>Fixed
      Assigned toNone=>bothner
    Tue 15 Mar 2016 01:08:06 AM UTCbothnerStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1