Commit bb5f52a4 authored by carlosperate's avatar carlosperate

Fix issue with variables not recognising variable type change correctly.

parent 1fc41c44
...@@ -175,28 +175,24 @@ Blockly.Blocks['variables_set'] = { ...@@ -175,28 +175,24 @@ Blockly.Blocks['variables_set'] = {
var varName = this.getFieldValue('VAR'); var varName = this.getFieldValue('VAR');
// Check what this block type should be // Check what this block type should be
var varType = Blockly.StaticTyping.getChildBlockType(this); var thisBlockType = Blockly.StaticTyping.getChildBlockType(this);
// Check if variable has been defined already // Check if variable has been defined already
var unique = true; var varType = Blockly.StaticTyping.findListVarType(varName, existingVars);
for (var name in existingVars) { if (varType === null) {
if (name == varName) { // This block var has not been encountered before, so return type
unique = false;
break;
}
}
// Only set the type if the variable has not been defined before
if (unique) {
this.setWarningText(null); this.setWarningText(null);
return varType; return thisBlockType;
} else if ( (existingVars[varName] != varType) && } else if ((existingVars[varName] !== thisBlockType) &&
(this.getChildren().length == 0) ) { (this.getChildren().length > 0)) {
// Variable name defined before, but only set warning if there are child
// blocks
this.setWarningText('This block is using a different type than what ' + this.setWarningText('This block is using a different type than what ' +
'was set on the first use of this variable.\nFirst use type: ' + 'was set on the first use of this variable.\nFirst use type: ' +
existingVars[varName] + '\nThis block type: ' + varType); existingVars[varName] + '\nThis block type: ' + thisBlockType);
return null; return null;
} else { } else {
// Variable defined before, but it is the same type, or block is empty
this.setWarningText(null); this.setWarningText(null);
return null; return null;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment