Skip to content

Commit

Permalink
Semantic: list pattern items
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Apr 21, 2024
1 parent 2d5c399 commit af8a009
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/scope/std.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const preludeVid = vidFromString('std::prelude')
// TODO: lack of std types must throw notFoundError
export const bool: VidType = { kind: 'vid-type', identifier: vidFromString('std::bool::Bool'), typeArgs: [] }
export const string: VidType = { kind: 'vid-type', identifier: vidFromString('std::string::String'), typeArgs: [] }
export const list: VidType = { kind: 'vid-type', identifier: vidFromString('std::list::List'), typeArgs: [holeType] }

export const show: VidType = { kind: 'vid-type', identifier: vidFromString('std::io::show::Show'), typeArgs: [] }
export const trace: VidType = { kind: 'vid-type', identifier: vidFromString('std::io::trace::Trace'), typeArgs: [] }
Expand Down
17 changes: 14 additions & 3 deletions src/semantic/match.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ConPattern, Pattern } from '../ast/match'
import { Name } from '../ast/operand'
import { Context, addError, defKey } from '../scope'
import { idToVid, vidToString } from '../scope/util'
import { list } from '../scope/std'
import { idToVid, vidEq, vidToString } from '../scope/util'
import { NameDef, resolveVid } from '../scope/vid'
import { VidType, VirtualFnType, VirtualType, isAssignable } from '../typecheck'
import { makeGenericMapOverStructure, resolveType } from '../typecheck/generic'
Expand Down Expand Up @@ -40,8 +41,18 @@ export const checkPattern = (
addError(ctx, unexpectedRefutablePatternError(ctx, pattern.expr))
break
}
// TODO: check item patterns
expr.type = unknownType
if (!(expectedType.kind === 'vid-type' && vidEq(expectedType.identifier, list.identifier))) {
addError(ctx, typeError(ctx, pattern, expectedType, list))
expr.type = unknownType
break
}
expr.type = expectedType

const itemType = expectedType.typeArgs[0]
expr.itemPatterns.forEach(p => {
checkPattern(p, itemType, ctx, refutable)
})

break
case 'con-pattern':
if (expectedType.kind !== 'vid-type') {
Expand Down

0 comments on commit af8a009

Please sign in to comment.