@malloydata/malloy 0.0.159-dev240805173126 → 0.0.159

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.
@@ -44,9 +44,27 @@ class HasParameter extends malloy_element_1.MalloyElement {
44
44
  const constant = this.default.constantValue();
45
45
  if (this.type &&
46
46
  this.type !== constant.dataType &&
47
+ constant.dataType !== 'null' &&
47
48
  constant.dataType !== 'error') {
48
49
  this.default.log(`Default value for parameter does not match declared type \`${this.type}\``);
49
50
  }
51
+ if (constant.dataType === 'null') {
52
+ if (this.type) {
53
+ return {
54
+ value: constant.value,
55
+ name: this.name,
56
+ type: this.type,
57
+ };
58
+ }
59
+ else {
60
+ this.default.log("Default value cannot have type `null` unless parameter type is also specified");
61
+ return {
62
+ value: constant.value,
63
+ name: this.name,
64
+ type: 'error',
65
+ };
66
+ }
67
+ }
50
68
  if (!(0, malloy_types_1.isCastType)(constant.dataType) && constant.dataType !== 'error') {
51
69
  this.default.log(`Default value cannot have type \`${constant.dataType}\``);
52
70
  return {
@@ -8,6 +8,7 @@ export declare abstract class SpaceParam extends SpaceEntry {
8
8
  export declare class AbstractParameter extends SpaceParam {
9
9
  readonly astParam: HasParameter;
10
10
  constructor(astParam: HasParameter);
11
+ _parameter: Parameter | undefined;
11
12
  parameter(): Parameter;
12
13
  typeDesc(): TypeDesc;
13
14
  }
@@ -35,15 +35,18 @@ class AbstractParameter extends SpaceParam {
35
35
  constructor(astParam) {
36
36
  super();
37
37
  this.astParam = astParam;
38
+ this._parameter = undefined;
38
39
  }
39
40
  parameter() {
40
- return this.astParam.parameter();
41
+ if (this._parameter !== undefined)
42
+ return this._parameter;
43
+ this._parameter = this.astParam.parameter();
44
+ return this._parameter;
41
45
  }
42
46
  typeDesc() {
43
- const type = this.astParam.type || 'error';
44
- // TODO Not sure whether params are considered "input space". It seems like they
45
- // could be input or constant, depending on usage.
46
- return { dataType: type, expressionType: 'scalar', evalSpace: 'input' };
47
+ var _a;
48
+ const type = (_a = this.parameter().type) !== null && _a !== void 0 ? _a : 'error';
49
+ return { dataType: type, expressionType: 'scalar', evalSpace: 'constant' };
47
50
  }
48
51
  }
49
52
  exports.AbstractParameter = AbstractParameter;
@@ -43,7 +43,28 @@ describe('parameters', () => {
43
43
  expect((0, test_translator_1.markSource) `
44
44
  ##! experimental.parameters
45
45
  source: ab_new(param is null) is ab
46
- `).translationToFailWith('Default value cannot have type `null`');
46
+ `).translationToFailWith('Default value cannot have type `null` unless parameter type is also specified');
47
+ });
48
+ test('allowed to write null::string', () => {
49
+ expect(`
50
+ ##! experimental.parameters
51
+ source: ab_new(param is null::string) is ab
52
+ `).toTranslate();
53
+ });
54
+ test('allowed to write ::string is null', () => {
55
+ expect(`
56
+ ##! experimental.parameters
57
+ source: ab_new(param::string is null) is ab
58
+ `).toTranslate();
59
+ });
60
+ test('can use param in null equality expression', () => {
61
+ expect(`
62
+ ##! experimental.parameters
63
+ source: ab_new(param is null::string) is ab extend {
64
+ where: param = null
65
+ }
66
+ run: ab_new(param is "foo") -> { select: * } -> { select: * }
67
+ `).toTranslate();
47
68
  });
48
69
  test('error if paramter type is range', () => {
49
70
  expect((0, test_translator_1.markSource) `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.159-dev240805173126",
3
+ "version": "0.0.159",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",