Skip to content

Commit

Permalink
Semantic: check con-pattern visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Mar 6, 2024
1 parent 455feea commit 73dfd61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/scope/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export const vidEq = (a: VirtualIdentifier, b: VirtualIdentifier): boolean => {
return true
}

export const vidScopeToString = (vid: VirtualIdentifier) => vidToString(vidFromScope(vid))

export const vidFromScope = (vid: VirtualIdentifier): VirtualIdentifier => ({ names: vid.names.slice(0, -1) })

export const idToVid = (id: Identifier): VirtualIdentifier => ({ names: id.names.map(s => s.value) })
Expand Down
7 changes: 6 additions & 1 deletion src/semantic/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const checkPattern = (pattern: Pattern, expectedType: VirtualType, ctx: C
}

/**
* @returns a list of definied names within con pattern (recursive included)
* @returns a list of definied names within con pattern (including recursive)
*/
const checkConPattern = (pattern: ConPattern, expectedType: VidType, ctx: Context): Name[] => {
const defs: Name[] = []
Expand Down Expand Up @@ -86,6 +86,11 @@ const checkConPattern = (pattern: ConPattern, expectedType: VidType, ctx: Contex
addError(ctx, notFoundError(ctx, fp, fp.name.value, 'field'))
return []
}
if (!field.pub && ctx.moduleStack.at(-1)! !== ref.module) {
const typeVid = vidToString(vidFromScope(ref.vid))
const msg = `field \`${fp.name.value}\` is private in type \`${typeVid}\``
addError(ctx, semanticError(ctx, fp, msg))
}

field.name.type = resolveType(field.type!, [conGenericMap], ctx)

Expand Down

0 comments on commit 73dfd61

Please sign in to comment.