I have some questions about extraReferenceTypeChecks option. Due to severe complexity of compiler theory and to the fact, that I have superficial knowledge there, I can't exactly tell whether code examples below are "not an issue" or not. To me they look like bugs, and I'm sorry for taking your time, if they aren't.
class Parent {}
class Child extends Parent {}
function returnChildTuple() as [Child] {
return [new Child()];
}
function returnParentTuple1() as [Parent] {
// OK
return [new Child()];
}
function returnParentTuple2() as [Parent] {
// Unsafe return from $.returnParentTuple2: converting [Child] to [Parent] is not type safe
return returnChildTuple();
}
I'm seeing this since 2.0.114.
import Toybox.Lang;
function returnTupleAsArray(b as Boolean) as Array<Number> {
// Unsafe return from $.returnTupleAsArray: converting [Number] or [] to Array<Number> is not type safe
return b ? [0] : [];
}
Though some other code, that calls returnTupleAsArray, may break returned tuples' typing, the code in general should be safe, as return type of returnTupleAsArray is array, not tuple, and caller will treat result as array.
import Toybox.Lang;
var arrayOfNumbers as Array<Number> = [];
function updateArrayOfNumbers1() as Void {
// OK
arrayOfNumbers = [0];
}
function updateArrayOfNumbers2() as Void {
var numberTuple = [0];
// Unsafe assignment to arrayOfNumbers: assigning [Number] to Array<Number> is not type safe
arrayOfNumbers = numberTuple;
}
I don't expect warning for updateArrayOfNumbers2, as this function is basically the same as updateArrayOfNumbers1.
import Toybox.Lang;
function updateArray1(array as Array<Number>, value1 as Number?, value2 as Number?) as Void {
// Invalid assignment to array[0]. Expected Number but got Null or Number - OK
array[0] = value1;
// array is Array<Null or Number> now - OK
// No warnings - OK
array[1] = value2;
}
function updateArray2(array as Array<[Numeric]>, value1 as [Number]?, value2 as [Number]?) as Void {
// Invalid assignment to array[0]. Expected [Number or Long or Float or Double] but got Null or [Number] - OK
array[0] = value1;
// array is Array<Null or [Numeric] or [Number]> now - OK
// Unsafe assignment to array[1]: assigning Null or [Number] to Null or [Number or Long or Float or Double] or [Number] is not type safe
array[1] = value2;
}
I've asked about no warnings for array[1] in updateArray1 code last week, and it was closed as "works as intended" (that is OK), but my real code is a bit more complex and looks more like updateArray2, and 2.0.114 introduces a warning for array[1], that I don't expect to see now, just like in updateArray1.
Thank you!
I have some questions about
extraReferenceTypeChecksoption. Due to severe complexity of compiler theory and to the fact, that I have superficial knowledge there, I can't exactly tell whether code examples below are "not an issue" or not. To me they look like bugs, and I'm sorry for taking your time, if they aren't.I'm seeing this since 2.0.114.
Though some other code, that calls
returnTupleAsArray, may break returned tuples' typing, the code in general should be safe, as return type ofreturnTupleAsArrayis array, not tuple, and caller will treat result as array.I don't expect warning for
updateArrayOfNumbers2, as this function is basically the same asupdateArrayOfNumbers1.I've asked about no warnings for
array[1]inupdateArray1code last week, and it was closed as "works as intended" (that is OK), but my real code is a bit more complex and looks more likeupdateArray2, and 2.0.114 introduces a warning forarray[1], that I don't expect to see now, just like inupdateArray1.Thank you!