History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-698
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Rodrigo B. de Oliveira
Reporter: Dominik Zablotny
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Boo

return from constructor

Created: 12/Mar/06 10:47 PM   Updated: 15/Mar/06 07:09 AM
Component/s: Compiler
Affects Version/s: 0.7
Fix Version/s: 0.7.6

Time Tracking:
Not Specified

File Attachments: 1. File bootest.boo (0.1 kb)

Environment: linux ubuntu dapper


 Description  « Hide
Compiler behaves strange when there is return statement within class constructor.
Example:

class Gee:
public x as string
def constructor():
x = "foo"
return
x = "bar"

a = Gee()
print a.x

Results in:

bootest.boo(8,9): BCE0055: Internal compiler error: Object reference not set to an instance of an object.
1 error(s).

In some other case, compiler haven't crashed, but the code had infinite loop in that place starting constructor from the beginning over and over again (despite what Linus says, it takes quite long to execute)
I can live without "return" in constructor, but error should be properly signalled. C# just skips the rest of constructor and returns new object, which IMHO makes sense. Here is C# sample:

class Gee
{
public string x;
public Gee()

{ x = "foo"; return; x = "bar"; }

}

class HelloWorld
{
static void Main(string[] args)

{ Gee a = new Gee(); System.Console.WriteLine(a.x); }

}

It compiles with warning about unreachable code and prints "foo"



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Dominik Zablotny - 12/Mar/06 10:52 PM
example with corrected indentation

Arron Washington - 15/Mar/06 02:32 AM
I believe this issue is also related to emitting bad IL code, spawning this epic saga in the boolang group:
http://groups.google.com/group/boolang/browse_frm/thread/c4af0b5bb7ac83d1/cb93a711dfe46cd4#cb93a711dfe46cd4

Here's a sample that tries to produce bad IL.

class zat:
def foo():
return 1
def constructor():
foo()
return

Both problems stem from use of the "return" keyword in an object constructor.

Since it just had its first real victim (see thread), I don't think ignoring this issue would be wise.


Rodrigo B. de Oliveira - 15/Mar/06 07:09 AM
thanks for the report, Dominik!
thanks for the heads up, Betson!