Skip to content

Commit afed6db

Browse files
committed
fix(diagnostics): correct overriding of imported variables in suite variables
fixes #424
1 parent 1f23559 commit afed6db

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

packages/robot/src/robotcode/robot/diagnostics/entities.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ class VariableDefinitionType(Enum):
179179
@dataclass
180180
class VariableDefinition(SourceEntity):
181181
name: str
182-
name_token: Optional[Token]
182+
name_token: Optional[Token] # TODO: this is not needed anymore, but kept for compatibility
183+
183184
type: VariableDefinitionType = VariableDefinitionType.VARIABLE
184185

185186
has_value: bool = field(default=False, compare=False)

packages/robot/src/robotcode/robot/diagnostics/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Error:
3939
INVALID_HEADER = "InvalidHeader"
4040
DEPRECATED_HEADER = "DeprecatedHeader"
4141
OVERRIDDEN_BY_COMMANDLINE = "OverriddenByCommandLine"
42+
OVERRIDES_IMPORTED_VARIABLE = "OverridesImportedVariable"
4243
VARIABLE_ALREADY_DEFINED = "VariableAlreadyDefined"
4344
VARIABLE_OVERRIDDEN = "VariableOverridden"
4445
MODEL_ERROR = "ModelError"

packages/robot/src/robotcode/robot/diagnostics/namespace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,8 @@ def yield_variables(
11161116
else []
11171117
),
11181118
[] if skip_global_variables or skip_commandline_variables else self.get_command_line_variables(),
1119-
[] if skip_global_variables else self.get_own_variables(),
11201119
[] if skip_global_variables else self.get_imported_variables(),
1120+
[] if skip_global_variables else self.get_own_variables(),
11211121
[] if skip_global_variables else self.get_builtin_variables(),
11221122
)
11231123
)

packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,27 @@ def _visit_Variable(self, node: Variable) -> None: # noqa: N802
234234
)
235235

236236
add_to_references = True
237+
238+
if existing_var is not None and existing_var.type == VariableDefinitionType.IMPORTED_VARIABLE:
239+
self._append_diagnostics(
240+
r,
241+
"Overrides imported variable.",
242+
DiagnosticSeverity.WARNING,
243+
Error.OVERRIDES_IMPORTED_VARIABLE,
244+
related_information=[
245+
DiagnosticRelatedInformation(
246+
location=Location(
247+
uri=str(Uri.from_path(existing_var.source)),
248+
range=existing_var.range,
249+
),
250+
message="Already defined here.",
251+
)
252+
]
253+
if existing_var.source
254+
else None,
255+
)
256+
existing_var = None
257+
237258
first_overidden_reference: Optional[VariableDefinition] = None
238259
if existing_var is not None:
239260
self._variable_references[existing_var].add(Location(self._namespace.document_uri, r))

0 commit comments

Comments
 (0)