diff --git a/src/scope/util.ts b/src/scope/util.ts index 417ac33d..864ab554 100644 --- a/src/scope/util.ts +++ b/src/scope/util.ts @@ -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) }) diff --git a/src/semantic/match.ts b/src/semantic/match.ts index 31bc7d2b..c6b8909b 100644 --- a/src/semantic/match.ts +++ b/src/semantic/match.ts @@ -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[] = [] @@ -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)