cqcallaw / newt

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

Consider how to avoid lookup problems with type shadowing #54

Open cqcallaw opened 8 years ago

cqcallaw commented 8 years ago

(from Lao)

Type Person :: Struct { # type_id = 1, canonicalized_name = "::Person"
    name: str
    age: int
}

var guy := @Person with { name = 'jon' age = 65 }

inner_scope = (b: bool) -> {
    Type Person :: Either { # type_id = 2, canonicalized_name = ::#Anoymous_FN_line8char15::Person"
      Joe: Unit
      Maria: Unit
      Larry: Unit
    }

    var p1 := guy
    var p2 := @Person # defaults to Joe, whatever

    set p1 = p2 # should be type error, p1 and p2 have different types
}
cqcallaw commented 8 years ago

A simplified example:

# type aliases shouldn't shadow root types
a { 
    s:string
}

b {
    a {
        c:a #it is assumed that type specifiers are always fully qualified, thus this 'a' references the top-level type
    }
}