Bytes is a tightly packed array of bytes1.
Since Solidity 0.5.0 this change was introduced :
Type Checker: Disallow conversions between bytesX and uintY of
different size.
Given that the current doc states that :
uint and int are aliases for uint256 and int256, respectively.
Your syntax tries to cast a bytes1 to uint256, this is forbidden since 0.5.0.
You can achieve your goal by just being more precise on the types, see this example :
pragma solidity ^0.8;
contract MyContract {
function bytesToUint(bytes memory b) public pure returns (uint256){
uint256 number;
for(uint i=0;i<b.length;i++){
number = number + uint8(b[i]);
}
return number;
}
}
The only important change is uint8(b[i]) instead of uint(b[i[). Casting bytes1 to a type of equal length.
So for an explicit conversion from bytes (containing tightly packed bytes1) you need :
uint(uint8(b[i]))
But anyway, implicit conversion from uint8 to uint is perfectly fine as in the previous exemple.
Hope that helps !