cqcallaw / newt

The newt programming language
GNU General Public License v3.0
12 stars 2 forks source link

Consider semantics of types defined inside a scope #57

Closed cqcallaw closed 6 years ago

cqcallaw commented 8 years ago

Given the snippet

if (2 == 2) {
    b { m:string = "inner" }
}

It would be reasonable to expect b to be undefined outside the context of the body of the if block. newt currently defines this type in the parent scope, but it is a quirk of the implementation, rather than a considered design decision.

cqcallaw commented 8 years ago

See also #54

cqcallaw commented 8 years ago

As of this writing, this feature appears to require that Expression::GetTypeSpecifier be revised to return a Result (with potential errors) instead of a TypeSpecifier.

cqcallaw commented 6 years ago

Latest experimentation indicates the Right Thing(tm) appears to be happening. Example:

if (2 == 2) {
        b { m:string = "inner" }
        r := @b
        print(r.m) # works
}

r2 := @b # type error