sql-typechecker 0.0.27 → 0.0.30

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.
package/out/cli.js CHANGED
@@ -241712,7 +241712,8 @@ function requireBoolean(e, t) {
241712
241712
  } else {
241713
241713
  throw new TypeMismatch(e, {
241714
241714
  expected: BuiltinTypes.Boolean,
241715
- actual: t
241715
+ actual: t,
241716
+ mess: "Requiring boolean"
241716
241717
  });
241717
241718
  }
241718
241719
  }
@@ -241784,7 +241785,7 @@ function cast(e, source, target, casttype) {
241784
241785
  }
241785
241786
  function castRecords(e, source, target, casttype) {
241786
241787
  if (source.fields.length !== target.fields.length) {
241787
- throw new TypeMismatch(e, {expected: source, actual: target});
241788
+ throw new TypeMismatch(e, {expected: source, actual: target}, "Amount of fields is not the same");
241788
241789
  }
241789
241790
  source.fields.forEach((sf, i) => {
241790
241791
  const tf = target.fields[i];
@@ -241793,14 +241794,15 @@ function castRecords(e, source, target, casttype) {
241793
241794
  }
241794
241795
  function unifyRecords(e, source, target) {
241795
241796
  if (source.fields.length !== target.fields.length) {
241796
- throw new TypeMismatch(e, {expected: source, actual: target});
241797
+ throw new TypeMismatch(e, {expected: source, actual: target}, "Amount of fields is not the same");
241797
241798
  }
241798
241799
  const newFields = source.fields.map((sf, i) => {
241799
241800
  const tf = target.fields[i];
241800
- const t = unifySimples(e, sf.type, tf.type);
241801
+ const t = unifySimples(tf.expr || e, sf.type, tf.type);
241801
241802
  return {
241802
241803
  name: sf.name || tf.name,
241803
- type: t
241804
+ type: t,
241805
+ expr: tf.expr
241804
241806
  };
241805
241807
  });
241806
241808
  return {
@@ -241845,19 +241847,19 @@ function castSimples(e, source, target, type) {
241845
241847
  if (target.kind === "nullable") {
241846
241848
  return castSimples(e, source.typevar, target.typevar, type);
241847
241849
  } else {
241848
- throw new TypeMismatch(e, {expected: source, actual: target});
241850
+ throw new TypeMismatch(e, {expected: source, actual: target}, "Nullability is different");
241849
241851
  }
241850
241852
  } else if (source.kind === "array") {
241851
241853
  if (target.kind === "array" && source.subtype === target.subtype) {
241852
241854
  return castSimples(e, source.typevar, target.typevar, type);
241853
241855
  } else {
241854
- throw new TypeMismatch(e, {expected: source, actual: target});
241856
+ throw new TypeMismatch(e, {expected: source, actual: target}, "Can't unify array with non-array");
241855
241857
  }
241856
241858
  } else if (source.kind === "scalar") {
241857
241859
  if (target.kind === "scalar") {
241858
241860
  return castScalars(e, source, target, type);
241859
241861
  } else {
241860
- throw new TypeMismatch(e, {expected: source, actual: target});
241862
+ throw new TypeMismatch(e, {expected: source, actual: target}, "Can't unify scalar with non-scalar");
241861
241863
  }
241862
241864
  } else if (source.kind === "jsonknown") {
241863
241865
  if (target.kind === "jsonknown") {
@@ -241871,7 +241873,7 @@ function castSimples(e, source, target, type) {
241871
241873
  }
241872
241874
  return;
241873
241875
  } else {
241874
- throw new TypeMismatch(e, {expected: source, actual: target});
241876
+ throw new TypeMismatch(e, {expected: source, actual: target}, "Can't unify JSON with non-JSON");
241875
241877
  }
241876
241878
  } else {
241877
241879
  return checkAllCasesHandled(source);
@@ -241914,7 +241916,7 @@ function unifyCallGeneral(call, argTypes, expectedArgs, returnT) {
241914
241916
  function castScalars(e, source, target, type) {
241915
241917
  const matchingCast = findMatchingCast([source.name], source, target, type);
241916
241918
  if (matchingCast === null) {
241917
- throw new TypeMismatch(e, {expected: target, actual: source});
241919
+ throw new TypeMismatch(e, {expected: target, actual: source}, "Couldn't find matching cast");
241918
241920
  }
241919
241921
  }
241920
241922
  function findMatchingCast(visited, from, to, type) {
@@ -241976,7 +241978,11 @@ function doCreateTable(g, s) {
241976
241978
  } else {
241977
241979
  return acc.concat({
241978
241980
  name: c.name,
241979
- type: mkType(c.dataType, c.constraints || [])
241981
+ type: mkType(c.dataType, c.constraints || []),
241982
+ expr: {
241983
+ type: "null",
241984
+ _location: c._location
241985
+ }
241980
241986
  });
241981
241987
  }
241982
241988
  }, []);
@@ -242051,7 +242057,7 @@ function elabSelect(g, c, s) {
242051
242057
  const foundNullabilityInference = inferredNullability.find((inf) => eqQNames(inf.fromName, fr.name) && inf.fieldName === fi.name?.name);
242052
242058
  if (foundNullabilityInference && isNullable(fi.type)) {
242053
242059
  const t = foundNullabilityInference.isNull === true ? BuiltinTypes.Null : unnullify(fi.type);
242054
- return {name: fi.name, type: t};
242060
+ return {name: fi.name, type: t, expr: fi.expr};
242055
242061
  } else {
242056
242062
  return fi;
242057
242063
  }
@@ -242081,7 +242087,7 @@ function elabSelect(g, c, s) {
242081
242087
  if (c2.expr.type === "ref" && c2.expr.name === "*") {
242082
242088
  return t.fields;
242083
242089
  } else {
242084
- return [{name: n, type: t.fields[0].type}];
242090
+ return [{name: n, type: t.fields[0].type, expr: c2.expr}];
242085
242091
  }
242086
242092
  } else {
242087
242093
  if (c2.expr.type === "ref" && c2.expr.name === "*") {
@@ -242091,7 +242097,7 @@ function elabSelect(g, c, s) {
242091
242097
  }
242092
242098
  }
242093
242099
  }
242094
- return [{name: n, type: t}];
242100
+ return [{name: n, type: t, expr: c2.expr}];
242095
242101
  });
242096
242102
  return {
242097
242103
  kind: "record",
@@ -242115,7 +242121,7 @@ function elabSelect(g, c, s) {
242115
242121
  if (t === null) {
242116
242122
  throw new CantReduceToSimpleT(exp, t_);
242117
242123
  } else {
242118
- return {name: null, type: t};
242124
+ return {name: null, type: t, expr: exp};
242119
242125
  }
242120
242126
  });
242121
242127
  return {
@@ -242142,7 +242148,8 @@ function elabSelect(g, c, s) {
242142
242148
  fields: [
242143
242149
  {
242144
242150
  name: null,
242145
- type: res
242151
+ type: res,
242152
+ expr: s
242146
242153
  }
242147
242154
  ]
242148
242155
  };
@@ -242195,7 +242202,7 @@ function elabInsert(g, c, s) {
242195
242202
  }
242196
242203
  insertT.fields.forEach((insertField, i) => {
242197
242204
  const col = columns[i];
242198
- cast(s.insert, insertField.type, col.type, "assignment");
242205
+ cast(insertField.expr || s.insert, insertField.type, col.type, "assignment");
242199
242206
  });
242200
242207
  if (s.returning) {
242201
242208
  return {
@@ -242208,7 +242215,8 @@ function elabInsert(g, c, s) {
242208
242215
  } else {
242209
242216
  return {
242210
242217
  name: selectedCol.alias || deriveNameFromExpr(selectedCol.expr),
242211
- type: t
242218
+ type: t,
242219
+ expr: selectedCol.expr
242212
242220
  };
242213
242221
  }
242214
242222
  })
@@ -242246,7 +242254,8 @@ function elabDeleteOrUpdate(g, c, s) {
242246
242254
  } else {
242247
242255
  return {
242248
242256
  name: selectedCol.alias || deriveNameFromExpr(selectedCol.expr),
242249
- type: t
242257
+ type: t,
242258
+ expr: selectedCol.expr
242250
242259
  };
242251
242260
  }
242252
242261
  })
@@ -242839,7 +242848,11 @@ function elabCall(g, c, e) {
242839
242848
  if (valTSimple === null) {
242840
242849
  throw new CantReduceToSimpleT(e.args[i], argTypes[i]);
242841
242850
  }
242842
- record.fields.push({name: {name: key.value}, type: valTSimple});
242851
+ record.fields.push({
242852
+ name: {name: key.value},
242853
+ type: valTSimple,
242854
+ expr: e.args[i]
242855
+ });
242843
242856
  }
242844
242857
  return {kind: "jsonknown", record};
242845
242858
  } else {
@@ -243045,7 +243058,8 @@ function elabExpr(g, c, e) {
243045
243058
  if (unnulified.kind !== "array") {
243046
243059
  throw new TypeMismatch(e.array, {
243047
243060
  expected: arrayT,
243048
- actual: BuiltinTypeConstructors.Array(BuiltinTypes.AnyScalar)
243061
+ actual: BuiltinTypeConstructors.Array(BuiltinTypes.AnyScalar),
243062
+ mess: "Can't get array index from non-array type"
243049
243063
  });
243050
243064
  } else {
243051
243065
  return nullify(unnulified.typevar);
@@ -243176,7 +243190,7 @@ function nullifyRecord(s) {
243176
243190
  return {
243177
243191
  kind: "record",
243178
243192
  fields: s.fields.map((c) => ({
243179
- name: c.name,
243193
+ ...c,
243180
243194
  type: nullify(c.type)
243181
243195
  }))
243182
243196
  };
@@ -243556,11 +243570,12 @@ async function go() {
243556
243570
  if (err instanceof ErrorWithLocation && err.l !== void 0) {
243557
243571
  const found = findCode(st.code || "", err.l);
243558
243572
  if (found) {
243573
+ const prefix = found.lineNumber.toString() + " ";
243559
243574
  console.error("");
243560
243575
  console.error(`Typechecking error`);
243561
243576
  console.error("");
243562
- console.error(found.line);
243563
- console.error(import_lodash2.repeat(" ", found.range[0]) + import_lodash2.repeat("^", found.range[1] - found.range[0]));
243577
+ console.error(prefix + found.line);
243578
+ console.error(import_lodash2.repeat(" ", found.range[0] + prefix.length) + import_lodash2.repeat("^", found.range[1] - found.range[0]));
243564
243579
  }
243565
243580
  }
243566
243581
  console.error(err instanceof Error ? err.message : JSON.stringify(err));