Skip to content

Commit

Permalink
Handle TRecType in areEqual (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark1626 committed Jan 8, 2024
1 parent 806c53c commit f3735bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/typechecker/Subtyping.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ object Subtyping {
case (TStaticInt(v1), TStaticInt(v2)) => v1 == v2
case (_: TIndex, _: TIndex) => true
case (_: TFloat, _: TFloat) => true
case (TAlias(r1), t) => r1.toString == t.toString
case (t, TAlias(r1)) => t.toString == r1.toString
case _ => t1 == t2
}

Expand Down
17 changes: 17 additions & 0 deletions src/test/scala/TypeCheckerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,16 @@ class TypeCheckerSpec extends FunSpec {
""")
}

it("allow record as return value") {
typeCheck("""
record point { x: bit<32> }
def f(p: point): point = {
let np: point = { x=p.x + 1 };
return np;
}
""")
}

it("disallow ill-typed return values") {
assertThrows[UnexpectedSubtype] {
typeCheck("""
Expand Down Expand Up @@ -1502,6 +1512,13 @@ class TypeCheckerSpec extends FunSpec {
let x = k.p.x + 1;
""")
}
it("should not throw error on casting") {
typeCheck("""
record point { x: ubit<32> }
let a: point = {x=10};
let b: point = (a as point);
""")
}
}

describe("Record Literals") {
Expand Down

0 comments on commit f3735bc

Please sign in to comment.