Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Erroring out with the method/var name that has the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtm98 committed Aug 16, 2024
1 parent 490a197 commit 63d2449
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
8 changes: 4 additions & 4 deletions jaclang/compiler/passes/main/access_modifier_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,26 +205,26 @@ def enter_name(self, node: ast.Name) -> None:
# Accessing a private/protected member within the top level scope illegal.
if curr_class is None:
return self.report_error(
f"Error: Invalid access of {access_type} member.",
f'Error: Invalid access of {access_type} member "{node.sym_name}".',
node,
)

if curr_class != node.sym.parent_tab.owner:
if not is_portect: # private member accessed in a different class.
return self.report_error(
f"Error: Invalid access of {access_type} member.",
f'Error: Invalid access of {access_type} member "{node.sym_name}".',
node,
)
else: # Accessing a protected member, check we're in an inherited class.
if not self.is_class_inherited_from(curr_class, sym_owner):
return self.report_error(
f"Error: Invalid access of {access_type} member.",
f'Error: Invalid access of {access_type} member "{node.sym_name}".',
node,
)

elif isinstance(sym_owner, ast.Module) and sym_owner != curr_module:
# Accessing a private/public member in a different module.
return self.report_error(
f"Error: Invalid access of {access_type} member.",
f'Error: Invalid access of {access_type} member "{node.sym_name}".',
node,
)
54 changes: 27 additions & 27 deletions jaclang/compiler/passes/main/fuse_typeinfo_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

from __future__ import annotations

from typing import Callable, Optional, TypeVar
from typing import Callable, TypeVar

import jaclang.compiler.absyntree as ast
from jaclang.compiler.passes import Pass
from jaclang.compiler.symtable import Symbol
from jaclang.settings import settings
from jaclang.utils.helpers import pascal_to_snake
from jaclang.vendor.mypy.nodes import Node as VNode # bit of a hack
Expand Down Expand Up @@ -494,28 +493,29 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None:
): # TODO check why IndexSlice produce an issue
right.name_spec.sym = left.type_sym_tab.lookup(right.sym_name)

# NOTE: Note sure why we're inferring the symbol here instead of the sym table build pass
# I afraid that moving this there might break something.
def lookup_sym_from_node(self, node: ast.AstNode, member: str) -> Optional[Symbol]:
"""Recursively look for the symbol of a member from a given node."""
if isinstance(node, ast.AstSymbolNode):
if node.type_sym_tab is None:
return None
return node.type_sym_tab.lookup(member)

if isinstance(node, ast.AtomTrailer):
if node.is_attr: # <expr>.member access.
return self.lookup_sym_from_node(node.right, member)
elif isinstance(node.right, ast.IndexSlice):
# NOTE: if the 'node.target' is a variable of type list[T] the
# node.target.sym_type is "builtins.list[T]" string Not sure how
# to get the type_sym_tab of "T" from just the name itself. would
# be better if the symbols types are not just strings but references.
# For now I'll mark them as todos.
# TODO:
# case 1: expr[i] -> regular indexing.
# case 2: expr[i:j:k] -> returns a sublist.
# case 3: expr["str"] -> dictionary lookup.
pass

return None
# # TODO [Gamal]: Need to support getting the type of an expression
# # NOTE: Note sure why we're inferring the symbol here instead of the sym table build pass
# # I afraid that moving this there might break something.
# def lookup_sym_from_node(self, node: ast.AstNode, member: str) -> Optional[Symbol]:
# """Recursively look for the symbol of a member from a given node."""
# if isinstance(node, ast.AstSymbolNode):
# if node.type_sym_tab is None:
# return None
# return node.type_sym_tab.lookup(member)

# if isinstance(node, ast.AtomTrailer):
# if node.is_attr: # <expr>.member access.
# return self.lookup_sym_from_node(node.right, member)
# elif isinstance(node.right, ast.IndexSlice):
# # NOTE: if the 'node.target' is a variable of type list[T] the
# # node.target.sym_type is "builtins.list[T]" string Not sure how
# # to get the type_sym_tab of "T" from just the name itself. would
# # be better if the symbols types are not just strings but references.
# # For now I'll mark them as todos.
# # TODO:
# # case 1: expr[i] -> regular indexing.
# # case 2: expr[i:j:k] -> returns a sublist.
# # case 3: expr["str"] -> dictionary lookup.
# pass

# return None

0 comments on commit 63d2449

Please sign in to comment.