occam-verify-cli 0.0.531 → 0.0.533
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/bin/utilities/releaseContext.js +3 -3
- package/lib/assertion.js +60 -0
- package/lib/axiom.js +3 -3
- package/lib/axiomLemmaTheoremConjecture.js +5 -5
- package/lib/combinator.js +3 -3
- package/lib/conclusion.js +3 -3
- package/lib/conjecture.js +3 -3
- package/lib/consequence.js +3 -3
- package/lib/constants.js +1 -5
- package/lib/constructor.js +5 -5
- package/lib/context/file.js +3 -2
- package/lib/context/proof.js +1 -20
- package/lib/context/release/file.js +10 -10
- package/lib/equality.js +61 -29
- package/lib/label.js +3 -3
- package/lib/lemma.js +3 -3
- package/lib/premise.js +3 -3
- package/lib/rule.js +5 -5
- package/lib/supposition.js +3 -3
- package/lib/theorem.js +3 -3
- package/lib/type.js +6 -6
- package/lib/utilities/node.js +3 -3
- package/lib/variable.js +23 -3
- package/lib/verify/assertion/type.js +56 -68
- package/lib/verify/statement.js +83 -28
- package/package.json +1 -1
- package/src/{assertion/type.js → assertion.js} +3 -3
- package/src/axiom.js +1 -1
- package/src/axiomLemmaTheoremConjecture.js +4 -4
- package/src/combinator.js +3 -1
- package/src/conclusion.js +3 -1
- package/src/conjecture.js +1 -1
- package/src/consequence.js +3 -1
- package/src/constants.js +0 -1
- package/src/constructor.js +5 -3
- package/src/context/file.js +3 -1
- package/src/context/proof.js +0 -25
- package/src/context/release/file.js +10 -11
- package/src/equality.js +35 -39
- package/src/label.js +3 -1
- package/src/lemma.js +1 -1
- package/src/premise.js +3 -1
- package/src/rule.js +4 -4
- package/src/supposition.js +3 -1
- package/src/theorem.js +1 -1
- package/src/type.js +5 -5
- package/src/utilities/node.js +3 -2
- package/src/variable.js +18 -2
- package/src/verify/assertion/type.js +83 -82
- package/src/verify/statement.js +76 -22
- package/lib/assertion/type.js +0 -60
- package/lib/node/statement/equality.js +0 -16
- package/src/node/statement/equality.js +0 -10
package/src/equality.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import Variable from "./variable";
|
|
4
4
|
import verifyTerm from "./verify/term";
|
|
5
|
-
import equalityCombinator from "./ocmbinator/equality";
|
|
6
|
-
import equalityStatementNode from "./node/statement/equality";
|
|
7
5
|
|
|
8
6
|
import { nodeQuery } from "./utilities/query";
|
|
9
7
|
import { first, second } from "./utilities/array";
|
|
10
|
-
import { EQUALITY_DEPTH } from "./constants";
|
|
11
8
|
import { TERM_RULE_NAME } from "./ruleNames";
|
|
12
|
-
import {
|
|
9
|
+
import { verifyTermAsVariable } from "./verify/term";
|
|
13
10
|
|
|
14
11
|
const leftTermNodeQuery = nodeQuery("/statement/argument[0]/term!"),
|
|
15
12
|
rightTermNodeQuery = nodeQuery("/statement/argument[1]/term!");
|
|
@@ -88,40 +85,10 @@ export default class Equality {
|
|
|
88
85
|
return equates;
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
static fromProofStep(proofStep) {
|
|
92
|
-
let equality = null;
|
|
93
|
-
|
|
94
|
-
const statementNode = proofStep.getStatementNode();
|
|
95
|
-
|
|
96
|
-
if (statementNode !== null) {
|
|
97
|
-
const nodeA = statementNode, ///
|
|
98
|
-
nodeB = equalityStatementNode, ///
|
|
99
|
-
depth = EQUALITY_DEPTH,
|
|
100
|
-
nodeMatches = matcher.matchNode(nodeA, nodeB, depth);
|
|
101
|
-
|
|
102
|
-
if (nodeMatches) {
|
|
103
|
-
const leftTermNode = leftTermNodeQuery(statementNode),
|
|
104
|
-
rightTermNode = rightTermNodeQuery(statementNode);
|
|
105
|
-
|
|
106
|
-
equality = new Equality(leftTermNode, rightTermNode);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return equality;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
88
|
static fromStatementNode(statementNode, context) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
statementVerifiedAgainstCombinator = verifyStatementAgainstCombinator(statementNode, combinator, context);
|
|
118
|
-
|
|
119
|
-
if (statementVerifiedAgainstCombinator) {
|
|
120
|
-
const leftTermNode = leftTermNodeQuery(statementNode),
|
|
121
|
-
rightTermNode = rightTermNodeQuery(statementNode);
|
|
122
|
-
|
|
123
|
-
equality = new Equality(leftTermNode, rightTermNode);
|
|
124
|
-
}
|
|
89
|
+
const leftTermNode = leftTermNodeQuery(statementNode),
|
|
90
|
+
rightTermNode = rightTermNodeQuery(statementNode),
|
|
91
|
+
equality = equalityFromLeftTermNodeAndRightTermNode(leftTermNode, rightTermNode, context);
|
|
125
92
|
|
|
126
93
|
return equality;
|
|
127
94
|
}
|
|
@@ -264,12 +231,41 @@ function equalityFromLeftTermNodeAndRightTermNode(leftTermNode, rightTermNode, c
|
|
|
264
231
|
if (leftTermTypeEqualToRightTermType) {
|
|
265
232
|
equality = new Equality(leftTermNode, rightTermNode);
|
|
266
233
|
} else {
|
|
234
|
+
const leftTermTypeSubTypeOfRightTermType = leftTermType.isSubTypeOf(rightTermType);
|
|
235
|
+
|
|
236
|
+
if (false) {
|
|
237
|
+
///
|
|
238
|
+
} else if (leftTermTypeSubTypeOfRightTermType) {
|
|
239
|
+
const variables = [],
|
|
240
|
+
rightTermVerifiedAsVariable = verifyTermAsVariable(rightTermNode, variables, context);
|
|
241
|
+
|
|
242
|
+
if (rightTermVerifiedAsVariable) {
|
|
243
|
+
let rightVariable;
|
|
244
|
+
|
|
245
|
+
const firstVariable = first(variables);
|
|
246
|
+
|
|
247
|
+
rightVariable = firstVariable; ///
|
|
248
|
+
|
|
249
|
+
const rightVariableName = rightVariable.getName(),
|
|
250
|
+
rightName = rightVariableName, ///
|
|
251
|
+
rightType = leftTermType; ///
|
|
252
|
+
|
|
253
|
+
rightVariable = Variable.fromTypeAndName(rightType, rightName);
|
|
254
|
+
|
|
255
|
+
context.addVariable(rightVariable);
|
|
256
|
+
|
|
257
|
+
equality = new Equality(leftTermNode, rightTermNode);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (equality === null) {
|
|
267
263
|
const leftTermString = context.nodeAsString(leftTermNode),
|
|
268
264
|
rightTermString = context.nodeAsString(rightTermNode),
|
|
269
265
|
leftTermTypeName = leftTermType.getName(),
|
|
270
266
|
rightTermTypeName = rightTermType.getName();
|
|
271
267
|
|
|
272
|
-
context.error(`The left '${leftTermString}' term's '${leftTermTypeName}' type is not equal to the right '${rightTermString}' term's '${rightTermTypeName}' type.'`, leftTermNode);
|
|
268
|
+
context.error(`The left '${leftTermString}' term's '${leftTermTypeName}' type is not equal to the right '${rightTermString}' term's '${rightTermTypeName}' type and neither can be inferred.'`, leftTermNode);
|
|
273
269
|
}
|
|
274
270
|
}
|
|
275
271
|
|
package/src/label.js
CHANGED
|
@@ -34,8 +34,10 @@ export default class Label {
|
|
|
34
34
|
return json;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
static fromJSON(json,
|
|
37
|
+
static fromJSON(json, context) {
|
|
38
38
|
const labelString = json, ///
|
|
39
|
+
lexer = context.getLexer(),
|
|
40
|
+
parser = context.getParser(),
|
|
39
41
|
labelNode = labelNodeFromLabelString(labelString, lexer, parser),
|
|
40
42
|
node = labelNode, ///
|
|
41
43
|
label = new Label(node);
|
package/src/lemma.js
CHANGED
|
@@ -7,7 +7,7 @@ import { LEMMA_KIND } from "./kinds";
|
|
|
7
7
|
export default class Lemma extends AxiomLemmaTheoremConjecture {
|
|
8
8
|
static kind = LEMMA_KIND;
|
|
9
9
|
|
|
10
|
-
static fromJSON(json,
|
|
10
|
+
static fromJSON(json, context) { return AxiomLemmaTheoremConjecture.fromJSON(Lemma, json, context); }
|
|
11
11
|
|
|
12
12
|
static fromLabelsSuppositionsAndConsequence(labels, suppositions, consequence) { return AxiomLemmaTheoremConjecture.fromLabelsSuppositionsAndConsequence(Lemma, labels, suppositions, consequence); }
|
|
13
13
|
}
|
package/src/premise.js
CHANGED
|
@@ -116,9 +116,11 @@ export default class Premise {
|
|
|
116
116
|
return json;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
static fromJSON(json,
|
|
119
|
+
static fromJSON(json, context) {
|
|
120
120
|
const { metastatement } = json,
|
|
121
121
|
metastatementString = metastatement, ///
|
|
122
|
+
lexer = context.getLexer(),
|
|
123
|
+
parser = context.getParser(),
|
|
122
124
|
metastatementNode = metastatementNodeFromMetastatementString(metastatementString, lexer, parser),
|
|
123
125
|
premise = new Premise(metastatementNode);
|
|
124
126
|
|
package/src/rule.js
CHANGED
|
@@ -134,7 +134,7 @@ export default class Rule {
|
|
|
134
134
|
return json;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
static fromJSON(json,
|
|
137
|
+
static fromJSON(json, context) {
|
|
138
138
|
let rule;
|
|
139
139
|
|
|
140
140
|
let { labels } = json;
|
|
@@ -143,7 +143,7 @@ export default class Rule {
|
|
|
143
143
|
|
|
144
144
|
labels = labelsJSON.map((labelJSON) => {
|
|
145
145
|
const json = labelJSON, ///
|
|
146
|
-
label = Label.fromJSON(json,
|
|
146
|
+
label = Label.fromJSON(json, context);
|
|
147
147
|
|
|
148
148
|
return label;
|
|
149
149
|
});
|
|
@@ -154,7 +154,7 @@ export default class Rule {
|
|
|
154
154
|
|
|
155
155
|
premises = premisesJSON.map((premiseJSON) => {
|
|
156
156
|
const json = premiseJSON, ///
|
|
157
|
-
premise = Premise.fromJSON(json,
|
|
157
|
+
premise = Premise.fromJSON(json, context);
|
|
158
158
|
|
|
159
159
|
return premise;
|
|
160
160
|
});
|
|
@@ -165,7 +165,7 @@ export default class Rule {
|
|
|
165
165
|
|
|
166
166
|
json = conclusionJSON; ///
|
|
167
167
|
|
|
168
|
-
conclusion = Conclusion.fromJSON(json,
|
|
168
|
+
conclusion = Conclusion.fromJSON(json, context);
|
|
169
169
|
|
|
170
170
|
rule = new Rule(labels, premises, conclusion);
|
|
171
171
|
|
package/src/supposition.js
CHANGED
|
@@ -71,9 +71,11 @@ export default class Supposition {
|
|
|
71
71
|
return json;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
static fromJSON(json,
|
|
74
|
+
static fromJSON(json, context) {
|
|
75
75
|
const { statement } = json,
|
|
76
76
|
statementString = statement, ///
|
|
77
|
+
lexer = context.getLexer(),
|
|
78
|
+
parser = context.getParser(),
|
|
77
79
|
statementNode = statementNodeFromStatementString(statementString, lexer, parser),
|
|
78
80
|
supposition = new Supposition(statementNode);
|
|
79
81
|
|
package/src/theorem.js
CHANGED
|
@@ -7,7 +7,7 @@ import { THEOREM_KIND } from "./kinds";
|
|
|
7
7
|
export default class Theorem extends AxiomLemmaTheoremConjecture {
|
|
8
8
|
static kind = THEOREM_KIND;
|
|
9
9
|
|
|
10
|
-
static fromJSON(json,
|
|
10
|
+
static fromJSON(json, context) { return AxiomLemmaTheoremConjecture.fromJSON(Theorem, json, context); }
|
|
11
11
|
|
|
12
12
|
static fromLabelsSuppositionsAndConsequence(labels, suppositions, consequence) { return AxiomLemmaTheoremConjecture.fromLabelsSuppositionsAndConsequence(Theorem, labels, suppositions, consequence); }
|
|
13
13
|
}
|
package/src/type.js
CHANGED
|
@@ -124,14 +124,14 @@ export default class Type {
|
|
|
124
124
|
return json;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
static fromJSON(json,
|
|
127
|
+
static fromJSON(json, context) {
|
|
128
128
|
let type;
|
|
129
129
|
|
|
130
130
|
let { superType } = json;
|
|
131
131
|
|
|
132
132
|
const superTypeJSON = superType; ///
|
|
133
133
|
|
|
134
|
-
superType = superTypeFromSuperTypeJSON(superTypeJSON,
|
|
134
|
+
superType = superTypeFromSuperTypeJSON(superTypeJSON, context);
|
|
135
135
|
|
|
136
136
|
const { name } = json;
|
|
137
137
|
|
|
@@ -181,7 +181,7 @@ class ObjectType extends Type {
|
|
|
181
181
|
|
|
182
182
|
export const objectType = ObjectType.fromNothing();
|
|
183
183
|
|
|
184
|
-
function superTypeFromSuperTypeJSON(superTypeJSON,
|
|
184
|
+
function superTypeFromSuperTypeJSON(superTypeJSON, context) {
|
|
185
185
|
let superType;
|
|
186
186
|
|
|
187
187
|
const json = superTypeJSON, ///
|
|
@@ -191,11 +191,11 @@ function superTypeFromSuperTypeJSON(superTypeJSON, lexer, parser) {
|
|
|
191
191
|
superType = objectType; ///
|
|
192
192
|
} else {
|
|
193
193
|
const typeName = name, ///
|
|
194
|
-
type =
|
|
194
|
+
type = context.findTypeByTypeName(typeName);
|
|
195
195
|
|
|
196
196
|
superType = (type !== null) ?
|
|
197
197
|
type : ///
|
|
198
|
-
Type.fromJSON(json,
|
|
198
|
+
Type.fromJSON(json, context); ///
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
return superType;
|
package/src/utilities/node.js
CHANGED
|
@@ -65,9 +65,10 @@ function nodeFromContentAndRuleName(content, ruleName, lexer = florenceLexer, pa
|
|
|
65
65
|
const ruleMap = parser.getRuleMap(),
|
|
66
66
|
rule = ruleMap[ruleName],
|
|
67
67
|
tokens = lexer.tokenise(content),
|
|
68
|
-
node = parser.parse(tokens, rule)
|
|
68
|
+
node = parser.parse(tokens, rule),
|
|
69
|
+
nonTerminalNode = node; ///
|
|
69
70
|
|
|
70
|
-
rewriteNodes(
|
|
71
|
+
rewriteNodes(nonTerminalNode);
|
|
71
72
|
|
|
72
73
|
return node;
|
|
73
74
|
}
|
package/src/variable.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export default class Variable {
|
|
4
|
-
constructor(type, name) {
|
|
4
|
+
constructor(type, name, termNode) {
|
|
5
5
|
this.type = type;
|
|
6
6
|
this.name = name;
|
|
7
|
+
this.termNode = termNode;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
getType() {
|
|
@@ -14,6 +15,14 @@ export default class Variable {
|
|
|
14
15
|
return this.name;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
getTermNode() {
|
|
19
|
+
return this.termNode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isUndefined() {
|
|
23
|
+
return (this.termNode === null);
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
matchName(name) {
|
|
18
27
|
const matchesName = (this.name === name);
|
|
19
28
|
|
|
@@ -28,7 +37,14 @@ export default class Variable {
|
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
static fromTypeAndName(type, name) {
|
|
31
|
-
const
|
|
40
|
+
const termNode = null,
|
|
41
|
+
variable = new Variable(type, name, termNode);
|
|
42
|
+
|
|
43
|
+
return variable;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static fromTypeNameAndTermNode(type, name, termNode) {
|
|
47
|
+
const variable = new Variable(type, name, termNode);
|
|
32
48
|
|
|
33
49
|
return variable;
|
|
34
50
|
}
|
|
@@ -1,54 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Variable from "../../variable";
|
|
4
|
-
import
|
|
4
|
+
import Assertion from "../../assertion";
|
|
5
5
|
|
|
6
6
|
import { first } from "../../utilities/array";
|
|
7
|
-
import { verifyTermAsVariable } from "../../verify/term";
|
|
8
7
|
import { nodeQuery, typeNameFromTypeNode } from "../../utilities/query";
|
|
8
|
+
import { verifyTermAsVariable, verifyTermAgainstConstructors } from "../../verify/term";
|
|
9
9
|
|
|
10
10
|
const termNodeQuery = nodeQuery("/typeAssertion/term"),
|
|
11
11
|
typeNodeQuery = nodeQuery("/typeAssertion/type");
|
|
12
12
|
|
|
13
|
-
export default function verifyTypeAssertion(typeAssertionNode, assertions, derived,
|
|
13
|
+
export default function verifyTypeAssertion(typeAssertionNode, assertions, derived, context) {
|
|
14
14
|
let typeAssertionVerified = false;
|
|
15
15
|
|
|
16
|
-
const typeAssertionString =
|
|
16
|
+
const typeAssertionString = context.nodeAsString(typeAssertionNode);
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
context.debug(`Verifying the '${typeAssertionString}' type assertion...`, typeAssertionNode);
|
|
19
19
|
|
|
20
20
|
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
21
21
|
typeName = typeNameFromTypeNode(typeNode),
|
|
22
|
-
typePresent =
|
|
22
|
+
typePresent = context.isTypePresentByTypeName(typeName);
|
|
23
23
|
|
|
24
24
|
if (!typePresent) {
|
|
25
|
-
|
|
25
|
+
context.error(`The ${typeName} type is not present.`, typeAssertionNode);
|
|
26
26
|
} else {
|
|
27
27
|
if (!typeAssertionVerified) {
|
|
28
|
-
const variableTypeAssertionVerified = verifyVariableTypeAssertion(typeAssertionNode, assertions, derived,
|
|
28
|
+
const variableTypeAssertionVerified = verifyVariableTypeAssertion(typeAssertionNode, assertions, derived, context);
|
|
29
29
|
|
|
30
30
|
typeAssertionVerified = variableTypeAssertionVerified; ///
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
if (!typeAssertionVerified) {
|
|
34
|
+
const termTypeAssertionVerified = verifyTermTypeAssertion(typeAssertionNode, context);
|
|
35
|
+
|
|
36
|
+
typeAssertionVerified = termTypeAssertionVerified; ///
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (typeAssertionVerified) {
|
|
41
|
-
|
|
41
|
+
context.info(`Verified the '${typeAssertionString}' statement type assertion.`, typeAssertionNode);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
return typeAssertionVerified;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function verifyVariableTypeAssertion(typeAssertionNode, assertions, derived,
|
|
47
|
+
function verifyVariableTypeAssertion(typeAssertionNode, assertions, derived, context) {
|
|
48
48
|
let variableTypeAssertionVerified = false;
|
|
49
49
|
|
|
50
|
-
const
|
|
51
|
-
variables = [],
|
|
50
|
+
const variables = [],
|
|
52
51
|
termNode = termNodeQuery(typeAssertionNode),
|
|
53
52
|
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context);
|
|
54
53
|
|
|
@@ -56,41 +55,45 @@ function verifyVariableTypeAssertion(typeAssertionNode, assertions, derived, pro
|
|
|
56
55
|
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
57
56
|
typeName = typeNameFromTypeNode(typeNode),
|
|
58
57
|
assertedTypeName = typeName, ///
|
|
59
|
-
assertedType =
|
|
60
|
-
firstVariable = first(variables),
|
|
61
|
-
variable = firstVariable, ///
|
|
62
|
-
variableName = variable.getName(),
|
|
63
|
-
variableType = variable.getType();
|
|
64
|
-
|
|
65
|
-
if (derived) {
|
|
66
|
-
const variableTypeEqualToOrSubTypeOfAssertedType = variableType.isEqualToOrSubTypeOf(assertedType);
|
|
58
|
+
assertedType = context.findTypeByTypeName(assertedTypeName);
|
|
67
59
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
variableTypeName = variableType.getName();
|
|
71
|
-
|
|
72
|
-
proofContext.error(`The '${variableName}' variable's '${variableTypeName}' type is not equal to or a sub-type of the '${assertedTypeName}' asserted type.`, typeAssertionNode);
|
|
73
|
-
} else {
|
|
74
|
-
variableTypeAssertionVerified = true;
|
|
75
|
-
}
|
|
60
|
+
if (assertedType === null) {
|
|
61
|
+
context.error(`The '${assertedTypeName}' asserted type is not present.`, typeAssertionNode);
|
|
76
62
|
} else {
|
|
77
|
-
const
|
|
63
|
+
const firstVariable = first(variables),
|
|
64
|
+
variable = firstVariable, ///
|
|
65
|
+
variableName = variable.getName(),
|
|
66
|
+
variableType = variable.getType();
|
|
67
|
+
|
|
68
|
+
if (derived) {
|
|
69
|
+
const variableTypeEqualToOrSubTypeOfAssertedType = variableType.isEqualToOrSubTypeOf(assertedType);
|
|
70
|
+
|
|
71
|
+
if (!variableTypeEqualToOrSubTypeOfAssertedType) {
|
|
72
|
+
const assertedTypeName = assertedType.getName(),
|
|
73
|
+
variableTypeName = variableType.getName();
|
|
74
|
+
|
|
75
|
+
context.error(`The '${variableName}' variable's '${variableTypeName}' type is not equal to or a sub-type of the '${assertedTypeName}' asserted type.`, typeAssertionNode);
|
|
76
|
+
} else {
|
|
77
|
+
variableTypeAssertionVerified = true;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const assertedTypeEqualToOrSubTypeOfVariableType = assertedType.isEqualToOrSubTypeOf(variableType);
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
if (!assertedTypeEqualToOrSubTypeOfVariableType) {
|
|
83
|
+
const assertedTypeName = assertedType.getName(),
|
|
84
|
+
variableTypeName = variableType.getName();
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
assertion = typeAssertion; ///
|
|
86
|
+
context.error(`The '${assertedTypeName}' asserted type is not equal to or a sub-type of the '${variableName}' variable's '${variableTypeName}' type.`, typeAssertionNode);
|
|
87
|
+
} else {
|
|
88
|
+
const type = assertedType, ///
|
|
89
|
+
name = variableName, ///
|
|
90
|
+
variable = Variable.fromTypeAndName(type, name),
|
|
91
|
+
assertion = Assertion.fromVariable(variable);
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
assertions.push(assertion);
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
variableTypeAssertionVerified = true;
|
|
96
|
+
}
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -98,40 +101,38 @@ function verifyVariableTypeAssertion(typeAssertionNode, assertions, derived, pro
|
|
|
98
101
|
return variableTypeAssertionVerified;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// return termTypeAssertionVerified;
|
|
136
|
-
// }
|
|
104
|
+
function verifyTermTypeAssertion(typeAssertionNode, context) {
|
|
105
|
+
let termTypeAssertionVerified = false;
|
|
106
|
+
|
|
107
|
+
const types = [],
|
|
108
|
+
termNode = termNodeQuery(typeAssertionNode),
|
|
109
|
+
termVerifiedAgainstConstructors = verifyTermAgainstConstructors(termNode, types, context);
|
|
110
|
+
|
|
111
|
+
if (termVerifiedAgainstConstructors) {
|
|
112
|
+
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
113
|
+
typeName = typeNameFromTypeNode(typeNode),
|
|
114
|
+
assertedTypeName = typeName, ///
|
|
115
|
+
assertedType = context.findTypeByTypeName(assertedTypeName);
|
|
116
|
+
|
|
117
|
+
if (assertedType === null) {
|
|
118
|
+
context.error(`The '${assertedTypeName}' asserted type is not present.`, typeAssertionNode);
|
|
119
|
+
} else {
|
|
120
|
+
const firstType = first(types),
|
|
121
|
+
termType = firstType, ///
|
|
122
|
+
termTypeIsEqualToAssertedType = termType.isEqualTo(assertedType);
|
|
123
|
+
|
|
124
|
+
if (!termTypeIsEqualToAssertedType) {
|
|
125
|
+
const termString = context.nodeAsString(termNode),
|
|
126
|
+
termTypeName = termType.getName(),
|
|
127
|
+
assertedTypeName = assertedType.getName();
|
|
128
|
+
|
|
129
|
+
context.error(`The '${assertedTypeName}' asserted type is not equal to the '${termString}' term's '${termTypeName}' type.`, typeAssertionNode);
|
|
130
|
+
} else {
|
|
131
|
+
termTypeAssertionVerified = true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return termTypeAssertionVerified;
|
|
137
|
+
}
|
|
137
138
|
|