Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3961,6 +3961,92 @@
"end": 147,
"name": "CompileError"
},
{
"code": 3039,
"diagnostic": "Invalid column reference",
"nodeOrToken": {
"id": 41,
"kind": "<primary-expression>",
"startPos": {
"offset": 138,
"line": 13,
"column": 9
},
"fullStart": 138,
"endPos": {
"offset": 140,
"line": 13,
"column": 11
},
"fullEnd": 141,
"start": 138,
"end": 140,
"expression": {
"id": 40,
"kind": "<variable>",
"startPos": {
"offset": 138,
"line": 13,
"column": 9
},
"fullStart": 138,
"endPos": {
"offset": 140,
"line": 13,
"column": 11
},
"fullEnd": 141,
"start": 138,
"end": 140,
"variable": {
"kind": "<identifier>",
"startPos": {
"offset": 138,
"line": 13,
"column": 9
},
"endPos": {
"offset": 140,
"line": 13,
"column": 11
},
"value": "id",
"leadingTrivia": [],
"trailingTrivia": [
{
"kind": "<space>",
"startPos": {
"offset": 140,
"line": 13,
"column": 11
},
"endPos": {
"offset": 141,
"line": 13,
"column": 12
},
"value": " ",
"leadingTrivia": [],
"trailingTrivia": [],
"leadingInvalid": [],
"trailingInvalid": [],
"isInvalid": false,
"start": 140,
"end": 141
}
],
"leadingInvalid": [],
"trailingInvalid": [],
"isInvalid": false,
"start": 138,
"end": 140
}
}
},
"start": 138,
"end": 140,
"name": "CompileError"
},
{
"code": 3034,
"diagnostic": "A Ref must appear top-level",
Expand Down Expand Up @@ -4469,6 +4555,92 @@
"start": 152,
"end": 170,
"name": "CompileError"
},
{
"code": 3039,
"diagnostic": "Invalid column reference",
"nodeOrToken": {
"id": 51,
"kind": "<primary-expression>",
"startPos": {
"offset": 157,
"line": 14,
"column": 9
},
"fullStart": 157,
"endPos": {
"offset": 161,
"line": 14,
"column": 13
},
"fullEnd": 162,
"start": 157,
"end": 161,
"expression": {
"id": 50,
"kind": "<variable>",
"startPos": {
"offset": 157,
"line": 14,
"column": 9
},
"fullStart": 157,
"endPos": {
"offset": 161,
"line": 14,
"column": 13
},
"fullEnd": 162,
"start": 157,
"end": 161,
"variable": {
"kind": "<identifier>",
"startPos": {
"offset": 157,
"line": 14,
"column": 9
},
"endPos": {
"offset": 161,
"line": 14,
"column": 13
},
"value": "code",
"leadingTrivia": [],
"trailingTrivia": [
{
"kind": "<space>",
"startPos": {
"offset": 161,
"line": 14,
"column": 13
},
"endPos": {
"offset": 162,
"line": 14,
"column": 14
},
"value": " ",
"leadingTrivia": [],
"trailingTrivia": [],
"leadingInvalid": [],
"trailingInvalid": [],
"isInvalid": false,
"start": 161,
"end": 162
}
],
"leadingInvalid": [],
"trailingInvalid": [],
"isInvalid": false,
"start": 157,
"end": 161
}
}
},
"start": 157,
"end": 161,
"name": "CompileError"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@/core/parser/utils';
import { ElementValidator } from '@/core/analyzer/validator/types';
import { isSimpleName, isValidColor, pickValidator, aggregateSettingList } from '@/core/analyzer/validator/utils';
import { isBinaryRelationship, isEqualTupleOperands } from '@/core/analyzer/utils';
import { destructureComplexVariable, destructureComplexVariableTuple, isBinaryRelationship, isEqualTupleOperands } from '@/core/analyzer/utils';
import SymbolTable from '@/core/analyzer/symbol/symbolTable';

export default class RefValidator implements ElementValidator {
Expand Down Expand Up @@ -97,6 +97,19 @@ export default class RefValidator implements ElementValidator {
errors.push(new CompileError(CompileErrorCode.INVALID_REF_FIELD, 'A Ref field must be a binary relationship', field.callee));
}

if (field.callee && isBinaryRelationship(field.callee)) {
const leftFragment = destructureComplexVariableTuple(field.callee.leftExpression).unwrap_or({ variables: [], tupleElements: [] });
const leftFragmentCount = leftFragment.variables.length + Math.min(leftFragment.tupleElements.length, 1);
const rightFragment = destructureComplexVariableTuple(field.callee.rightExpression).unwrap_or({ variables: [], tupleElements: [] });
const rightFragmentCount = rightFragment.variables.length + Math.min(rightFragment.tupleElements.length, 1);
if (leftFragmentCount < 2) {
errors.push(new CompileError(CompileErrorCode.INVALID_REF_FIELD, 'Invalid column reference', field.callee.leftExpression || field.callee));
}
if (rightFragmentCount < 2) {
errors.push(new CompileError(CompileErrorCode.INVALID_REF_FIELD, 'Invalid column reference', field.callee.rightExpression || field.callee));
}
}

if (field.callee && !isEqualTupleOperands(field.callee)) {
errors.push(new CompileError(CompileErrorCode.UNEQUAL_FIELDS_BINARY_REF, 'Unequal fields in ref endpoints', field.callee));
}
Expand Down