Added methods to check if a type is a number

This commit is contained in:
Sasha Koshka 2022-10-13 20:52:49 -04:00
parent 12755d3f85
commit dd29f69213
2 changed files with 56 additions and 57 deletions

View File

@ -42,23 +42,11 @@ func (literal IntLiteral) What () (what Type) {
// canBePassedAs returns true if this literal can be implicitly cast to the // canBePassedAs returns true if this literal can be implicitly cast to the
// specified type, and false if it can't. // specified type, and false if it can't.
func (literal IntLiteral) canBePassedAs (what Type) (allowed bool) { func (literal IntLiteral) canBePassedAs (what Type) (allowed bool) {
// must be a singlular value // can be passed to singular types that are signed numbers at a
if !what.isSingular() { return } // primitive level.
allowed =
// can be passed to types that are signed numbers at a primitive level. what.isSingular() &&
primitive := what.underlyingPrimitive() what.isSignedNumeric()
switch primitive {
case
&PrimitiveF64,
&PrimitiveF32,
&PrimitiveI64,
&PrimitiveI32,
&PrimitiveI16,
&PrimitiveI8,
&PrimitiveInt:
allowed = true
}
return return
} }