Wiki

Ticket #349 (closed defect: fixed)

Opened 10 years ago

Last modified 10 years ago

Internal error for forward reference

Reported by: Charles Owned by:
Priority: major Milestone:
Component: Cobra Compiler Version: 0.9.6
Keywords: Cc:

Description

The following code causes an internal error:

class A

    var _foo = B.bar


class B

    def bar as String is shared
        return ''

Note that the equivalent C# works fine:

class A {

	protected string _foo = B.Bar();
	
}

class B {

	public static string Bar() {
		return "";
	}

}

Though C# has no "var" at the member var level, nor "from var" for declaring properties.

Change History

Changed 10 years ago by Charles

Note that the error happens during "bind interface" on A and then _foo which causes a "bind implementation" for "B.bar", but B.bar is "not ready" because B has not yet had a "bind interface". This directly happens due to BoxMember.isUsed being set, but I haven't checked if it would happen further in the execution if .isUsed didn't trigger it.

It's kind of surprising that we don't run into this more often.

Changed 10 years ago by Charles

Changed 10 years ago by Charles

  • version changed from 0.9.4 to 0.9.6

Changed 10 years ago by Charles

  • status changed from new to closed
  • resolution set to fixed

Fixed in changeset:3093

The line is still not accepted, but it is now caught as an error and the error message gives 3 possible changes:

error: Cannot compile initialization expression at this point. Add an
explicit type to the `var` ("as <type>") or move to a `cue init` or change
the expression.

Changed 10 years ago by Charles

In the description, I said "The equivalent C#" but in fact there is no equivalent C# because there is no var type inference at the class member level. The C# code explicitly types the _foo member. I should have said "The closest C#..."

Note: See TracTickets for help on using tickets.