128 lines
No EOL
2.9 KiB
Text
128 lines
No EOL
2.9 KiB
Text
==== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements.ts (9 errors) ====
|
|
// return type of a function with multiple returns is the BCT of each return statement
|
|
// it is an error if there is no single BCT, these are error cases
|
|
|
|
function f1() {
|
|
~~~~~~~~~~~~~~~
|
|
if (true) {
|
|
~~~~~~~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else {
|
|
~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! No best common type exists among return expressions.
|
|
|
|
function f2() {
|
|
~~~~~~~~~~~~~~~
|
|
if (true) {
|
|
~~~~~~~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else if (false) {
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
return 2;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else {
|
|
~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! No best common type exists among return expressions.
|
|
|
|
function f3() {
|
|
~~~~~~~~~~~~~~~
|
|
try {
|
|
~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
catch (e) {
|
|
~~~~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! No best common type exists among return expressions.
|
|
|
|
function f4() {
|
|
~~~~~~~~~~~~~~~
|
|
try {
|
|
~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
catch (e) {
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
}
|
|
~~~~~
|
|
finally {
|
|
~~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! No best common type exists among return expressions.
|
|
|
|
function f5() {
|
|
~~~~~~~~~~~~~~~
|
|
return 1;
|
|
~~~~~~~~~~~~~
|
|
return '';
|
|
~~~~~~~~~~~~~~
|
|
}
|
|
~
|
|
!!! No best common type exists among return expressions.
|
|
|
|
function f6<T, U>(x: T, y:U) {
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
if (true) {
|
|
~~~~~~~~~~~~~~~
|
|
return x;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else {
|
|
~~~~~~~~~~~~
|
|
return y;
|
|
~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! No best common type exists among return expressions.
|
|
|
|
function f8<T extends U, U extends V, V>(x: T, y: U) {
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
~~~~~~~~~~~
|
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
~~~~~~~~~~~
|
|
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
|
if (true) {
|
|
~~~~~~~~~~~~~~~
|
|
return x;
|
|
~~~~~~~~~~~~~~~~~
|
|
} else {
|
|
~~~~~~~~~~~~
|
|
return y;
|
|
~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
}
|
|
~
|
|
!!! No best common type exists among return expressions.
|
|
|