make unassigned return a hint instead of an error

This commit is contained in:
Michal Moskal 2015-05-20 07:24:19 -07:00
Родитель 6283e16b26
Коммит e0a1be0007
3 изменённых файлов: 28 добавлений и 8 удалений

Просмотреть файл

@ -130,6 +130,7 @@ module TDev.AST {
private stableName: string;
private stableVersions : string[];
public tutorialWarning: string;
public _hint:string;
constructor() {
super()
@ -147,6 +148,25 @@ module TDev.AST {
else
return this._error;
}
public getHint()
{
var r:string = null
if (this.calcNode())
r = this.calcNode().hint
if (!r) return this._hint
if (this._hint) return r + "\n" + this._hint
return null
}
public addHint(msg:string)
{
if (!this._hint) this._hint = msg
else this._hint += "\n" + msg
}
public clearError()
{
this._error = null
this._hint = null
}
public debuggerRenderContext: {
isOnStackTrace ?: boolean;

Просмотреть файл

@ -479,12 +479,11 @@ module TDev
}
if (res == "" && node instanceof AST.Stmt) {
var calcNode = (<AST.Stmt>node).calcNode();
if (calcNode && calcNode.hint) {
calcNode.hint.split("\n").forEach(h => {
var hint = (<AST.Stmt>node).getHint()
if (hint)
hint.split("\n").forEach(h => {
res += this.message("hintMessage", Util.htmlEscape("\u270e " + h))
})
}
}
if (node.annotations)

Просмотреть файл

@ -1049,13 +1049,14 @@ module TDev.AST
this.updateStmtUsage(expr, "var");
}
private checkAssignment(node:AstNode, vars:LocalDef[])
private checkAssignment(node:Stmt, vars:LocalDef[])
{
var unassigned = vars.filter((v) => this.writtenLocals.indexOf(v) < 0);
if (unassigned.length > 0) {
this.setNodeError(node,
lf("TD127: output parameter{0:s} {1} need to be assigned to before the action finishes",
unassigned.length, unassigned.map((v) => "'" + v.getName() + "'").join(", ")))
node.addHint(
lf("parameter{0:s} {1} may be unassigned before the action finishes",
unassigned.length,
unassigned.map((v) => "'" + v.getName() + "'").join(", ")))
}
}