Skip to content

Commit

Permalink
refactor: remove unneeded index access
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed May 9, 2024
1 parent 4fefe5d commit 42f172b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/ast/bare-semantic-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Checker = {

function checkTypeName(aliased: ast.AliasedType): void {
const { alias, internal } = aliased
if (alias.length !== 0 && /^\d/.test(alias[0])) {
if (/^\d/.test(alias)) {
if (!internal) {
throw new CompilerError(
`the type name '${alias}' must not start with a figure or must be internal.`,
Expand Down Expand Up @@ -235,17 +235,16 @@ function checkNonVoid(c: Checker, type: ast.Type): void {
}

function checkUnionInvariants(c: Checker, type: ast.UnionType): void {
const tags = type.data
// check type uniqueness
const stringifiedTypes = new Set()
for (let i = 0; i < tags.length; i++) {
const stringifiedType = JSON.stringify(ast.withoutExtra(type.types[i]))
for (const ty of type.types) {
const stringifiedType = JSON.stringify(ast.withoutExtra(ty))
// NOTE: this dirty check is ok because we initialize
// every object in the same way (properties are in the same order)
if (stringifiedTypes.has(stringifiedType)) {
throw new CompilerError(
"a type cannot be repeated in an union.",
type.types[i].offset,
ty.offset,
)
}
stringifiedTypes.add(stringifiedType)
Expand Down

0 comments on commit 42f172b

Please sign in to comment.