@rsconcept/domain 1.4.4 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -218,14 +218,17 @@ const errorData = [
218
218
  ['pr1(X1)', { code: RSErrorCode.invalidProjectionTuple, from: 4, to: 6, params: ['pr1', 'ℬ(X1)'] }],
219
219
  ['pr1(debool(X1))', { code: RSErrorCode.invalidProjectionTuple, from: 4, to: 14, params: ['pr1', 'X1'] }],
220
220
  ['pr3(debool(S1))', { code: RSErrorCode.invalidProjectionTuple, from: 4, to: 14, params: ['pr3', 'X1×X1'] }],
221
- ['Fi1[X1](ℬ(X1))', { code: RSErrorCode.invalidFilterArgumentType, from: 8, to: 13, params: ['Fi1', 'ℬℬ(X1)'] }],
221
+ [
222
+ 'Fi1[X1](ℬ(X1))',
223
+ { code: RSErrorCode.invalidFilterArgumentType, from: 8, to: 13, params: ['Fi1', 'ℬℬ(X1)', 'ℬ(R0)'] }
224
+ ],
222
225
  ['Fi1[1](S1)', { code: RSErrorCode.invalidFilterParameterType, from: 4, to: 5, params: ['Z', 'ℬ(X1)', 'Fi1'] }],
223
226
  [
224
227
  'Fi1[X1](ℬ(X1)×X1)',
225
- { code: RSErrorCode.invalidFilterParameterType, from: 4, to: 6, params: ['ℬ(X1)', 'ℬℬ(X1)', 'Fi1'] }
228
+ { code: RSErrorCode.invalidFilterBooleanEchelon, from: 4, to: 6, params: ['Fi1', 'ℬ(X1)', 'ℬℬ(X1)'] }
226
229
  ],
227
- ['Fi3[X1](S1)', { code: RSErrorCode.invalidFilterArgumentType, from: 8, to: 10, params: ['Fi3', 'ℬ(X1×X1)'] }],
228
- ['Fi1[X1,X1](S1)', { code: RSErrorCode.invalidFilterArity, from: 0, to: 14 }],
230
+ ['Fi3[X1](S1)', { code: RSErrorCode.invalidFilterIndex, from: 8, to: 10, params: ['Fi3', 'ℬ(X1×X1)', '3', '2'] }],
231
+ ['Fi1[X1,X1](S1)', { code: RSErrorCode.invalidFilterArity, from: 7, to: 9, params: ['1', '2', 'Fi1'] }],
229
232
  [
230
233
  'Fi1,2[X1](S1)',
231
234
  { code: RSErrorCode.invalidFilterParameterType, from: 6, to: 8, params: ['ℬ(X1)', 'ℬ(X1×X1)', 'Fi1,2'] }
@@ -351,6 +351,9 @@ export class TypeAuditor {
351
351
  if (!type) {
352
352
  return this.onError(RSErrorCode.globalNotTyped, node, [alias]);
353
353
  }
354
+ if (type.typeID === TypeID.function || type.typeID === TypeID.predicate) {
355
+ return this.onError(RSErrorCode.globalFuncWithoutArgs, node, [alias]);
356
+ }
354
357
  return type;
355
358
  }
356
359
 
@@ -744,7 +747,12 @@ export class TypeAuditor {
744
747
  const indices = getNodeIndices(node);
745
748
  const tupleParam = indices.length === node.children.length - 1;
746
749
  if (!tupleParam && node.children.length > 2) {
747
- return this.onError(RSErrorCode.invalidFilterArity, node);
750
+ const extraParam = node.children[indices.length];
751
+ return this.onError(RSErrorCode.invalidFilterArity, extraParam ?? node, [
752
+ String(indices.length),
753
+ String(node.children.length - 1),
754
+ operator
755
+ ]);
748
756
  }
749
757
 
750
758
  const argument = this.childTypification(node, node.children.length - 1);
@@ -757,10 +765,12 @@ export class TypeAuditor {
757
765
  ) {
758
766
  return EmptySetT;
759
767
  }
768
+ const expectedArgument = this.expectedFilterArgumentLabel(indices);
760
769
  if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.tuple) {
761
770
  return this.onError(RSErrorCode.invalidFilterArgumentType, node.children[node.children.length - 1], [
762
- labelRSLangNode(node),
763
- labelType(argument)
771
+ operator,
772
+ labelType(argument),
773
+ expectedArgument
764
774
  ]);
765
775
  }
766
776
 
@@ -769,9 +779,11 @@ export class TypeAuditor {
769
779
  for (const index of indices) {
770
780
  const newBase = component(argBase, index);
771
781
  if (newBase === null) {
772
- return this.onError(RSErrorCode.invalidFilterArgumentType, node.children[node.children.length - 1], [
773
- labelRSLangNode(node),
774
- labelType(argument)
782
+ return this.onError(RSErrorCode.invalidFilterIndex, node.children[node.children.length - 1], [
783
+ operator,
784
+ labelType(argument),
785
+ String(index),
786
+ String(argBase.factors.length)
775
787
  ]);
776
788
  }
777
789
  bases.push(newBase);
@@ -783,12 +795,9 @@ export class TypeAuditor {
783
795
  if (param === null) {
784
796
  return null;
785
797
  }
798
+ const expectedParam = bool(bases[child]);
786
799
  if (param.typeID !== TypeID.collection || !checkCompatibility(bases[child], debool(param))) {
787
- return this.onError(RSErrorCode.invalidFilterParameterType, node.children[child], [
788
- labelType(param),
789
- labelType(bool(bases[child])),
790
- operator
791
- ]);
800
+ return this.reportFilterParameterError(node, child, param, expectedParam, operator);
792
801
  }
793
802
  }
794
803
  } else {
@@ -799,16 +808,46 @@ export class TypeAuditor {
799
808
  const paramType = param;
800
809
  const expected = bool(tuple(bases));
801
810
  if (paramType.typeID !== TypeID.collection || !checkCompatibility(expected, paramType)) {
802
- return this.onError(RSErrorCode.invalidFilterParameterType, node.children[0], [
803
- labelType(paramType),
804
- labelType(expected),
805
- operator
806
- ]);
811
+ return this.reportFilterParameterError(node, 0, paramType, expected, operator);
807
812
  }
808
813
  }
809
814
  return argument;
810
815
  }
811
816
 
817
+ private expectedFilterArgumentLabel(indices: number[]): string {
818
+ const maxIndex = Math.max(...indices, 0);
819
+ if (maxIndex <= 1) {
820
+ return labelType(bool({ typeID: TypeID.anyTypification }));
821
+ }
822
+ const factors: Typification[] = [];
823
+ for (let index = 1; index <= maxIndex; index++) {
824
+ factors.push({ typeID: TypeID.anyTypification });
825
+ }
826
+ return labelType(bool(tuple(factors)));
827
+ }
828
+
829
+ private reportFilterParameterError(
830
+ node: AstNode,
831
+ childIndex: number,
832
+ param: Typification,
833
+ expected: Typification,
834
+ operator: string
835
+ ): null {
836
+ const wrapped = bool(param);
837
+ if (checkEquality(wrapped, expected) || checkCompatibility(wrapped, expected)) {
838
+ return this.onError(RSErrorCode.invalidFilterBooleanEchelon, node.children[childIndex], [
839
+ operator,
840
+ labelType(param),
841
+ labelType(expected)
842
+ ]);
843
+ }
844
+ return this.onError(RSErrorCode.invalidFilterParameterType, node.children[childIndex], [
845
+ labelType(param),
846
+ labelType(expected),
847
+ operator
848
+ ]);
849
+ }
850
+
812
851
  private visitReduce(node: AstNode): ExpressionType | null {
813
852
  const argument = this.childTypification(node, 0);
814
853
  if (argument === null) {