Wiki

Ticket #350 (new enhancement)

Opened 4 years ago

Handle more forward references in `var` initialization expressions

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

Description

This forward reference:

class A

    var _foo = B.bar


class B

    def bar as String is shared
        return ''

Gives this error:

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.

Ideally, Cobra would handle this particular forward reference (and similar ones) since it looks fairly simple.

Further notes:

There is no equivalent C# because C# has no "var" type inference at the member var level, nor "from var" for declaring properties. The closest C# is this:

class A {

	protected string _foo = B.Bar();
	
}

class B {

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

}

Which works fine, but so does the equivalent Cobra:

    var _foo as String = B.bar

See ticket:349 for the original report on this, back when Cobra produced an internal error rather than a normal, informative error. Fix was in changeset:3093 and shows where the relevant code is--the call of _initExpr.bindImp from the _bindInt of BoxField.

Note: See TracTickets for help on using tickets.