Fixed type checking for string literals

The string builtin was incorrectly described, and
StringLiteral.canBePassedAs was checking the type actual instead of
the type points in the case of a reducible type.
This commit is contained in:
Sasha Koshka 2022-10-17 01:40:00 -04:00
parent a5b1385012
commit d6c8f57a81
3 changed files with 23 additions and 17 deletions

View File

@ -13,7 +13,7 @@ type DataSection struct {
// ToString returns all data stored within the data section, in string form. // ToString returns all data stored within the data section, in string form.
func (section DataSection) ToString (indent int) (output string) { func (section DataSection) ToString (indent int) (output string) {
output += doIndent(indent, "typeSection ") output += doIndent(indent, "dataSection ")
output += section.permission.ToString() + " " output += section.permission.ToString() + " "
output += section.where.ToString() output += section.where.ToString()
output += "\n" output += "\n"

View File

@ -211,8 +211,10 @@ func (literal StringLiteral) canBePassedAs (what Type) (allowed bool) {
if !what.isSingular() { return } if !what.isSingular() { return }
if reduced.kind != TypeKindVariableArray { return } if reduced.kind != TypeKindVariableArray { return }
what = reduced what = reduced
allowed = what.points.isNumeric()
} else {
allowed = what.isNumeric()
} }
allowed = what.isNumeric()
return return
} }

View File

@ -3,43 +3,43 @@ package analyzer
// This is a global, cannonical list of primitive and built-in types. // This is a global, cannonical list of primitive and built-in types.
// PrimitiveF32 is a 32 bit floating point primitive. // PrimitiveF32 is a 32 bit floating point primitive.
var PrimitiveF32 = createPrimitive("F32", Type {}) var PrimitiveF32 = createPrimitive("F32", Type { length: 1 })
// PrimitiveF64 is a 64 bit floating point primitive. // PrimitiveF64 is a 64 bit floating point primitive.
var PrimitiveF64 = createPrimitive("F64", Type {}) var PrimitiveF64 = createPrimitive("F64", Type { length: 1 })
// PrimitiveInt is a signed integer word primitive. // PrimitiveInt is a signed integer word primitive.
var PrimitiveInt = createPrimitive("Int", Type {}) var PrimitiveInt = createPrimitive("Int", Type { length: 1 })
// PrimitiveUInt is an unsigned integer word primitive. // PrimitiveUInt is an unsigned integer word primitive.
var PrimitiveUInt = createPrimitive("UInt", Type {}) var PrimitiveUInt = createPrimitive("UInt", Type { length: 1 })
// PrimitiveI8 is a signed 8 bit integer primitive. // PrimitiveI8 is a signed 8 bit integer primitive.
var PrimitiveI8 = createPrimitive("I8", Type {}) var PrimitiveI8 = createPrimitive("I8", Type { length: 1 })
// PrimitiveI16 is a signed 16 bit integer primitive. // PrimitiveI16 is a signed 16 bit integer primitive.
var PrimitiveI16 = createPrimitive("I16", Type {}) var PrimitiveI16 = createPrimitive("I16", Type { length: 1 })
// PrimitiveI32 is a signed 32 bit integer primitive. // PrimitiveI32 is a signed 32 bit integer primitive.
var PrimitiveI32 = createPrimitive("I32", Type {}) var PrimitiveI32 = createPrimitive("I32", Type { length: 1 })
// PrimitiveI64 is a signed 64 bit integer primitive. // PrimitiveI64 is a signed 64 bit integer primitive.
var PrimitiveI64 = createPrimitive("I64", Type {}) var PrimitiveI64 = createPrimitive("I64", Type { length: 1 })
// PrimitiveI8 is an unsigned 8 bit integer primitive. // PrimitiveI8 is an unsigned 8 bit integer primitive.
var PrimitiveU8 = createPrimitive("U8", Type {}) var PrimitiveU8 = createPrimitive("U8", Type { length: 1 })
// PrimitiveI16 is an unsigned 16 bit integer primitive. // PrimitiveI16 is an unsigned 16 bit integer primitive.
var PrimitiveU16 = createPrimitive("U16", Type {}) var PrimitiveU16 = createPrimitive("U16", Type { length: 1 })
// PrimitiveI32 is an unsigned 32 bit integer primitive. // PrimitiveI32 is an unsigned 32 bit integer primitive.
var PrimitiveU32 = createPrimitive("U32", Type {}) var PrimitiveU32 = createPrimitive("U32", Type { length: 1 })
// PrimitiveI64 is an unsigned 64 bit integer primitive. // PrimitiveI64 is an unsigned 64 bit integer primitive.
var PrimitiveU64 = createPrimitive("U64", Type {}) var PrimitiveU64 = createPrimitive("U64", Type { length: 1 })
// PrimitiveObj is a blank object primitive. // PrimitiveObj is a blank object primitive.
var PrimitiveObj = createPrimitive("Obj", Type {}) var PrimitiveObj = createPrimitive("Obj", Type { length: 1 })
// TODO: make these two be interface sections // TODO: make these two be interface sections
@ -52,8 +52,12 @@ var PrimitiveObj = createPrimitive("Obj", Type {})
// BuiltInString is a built in string type. It is a dynamic array of UTF-32 // BuiltInString is a built in string type. It is a dynamic array of UTF-32
// codepoints. // codepoints.
var BuiltInString = createPrimitive("String", Type { var BuiltInString = createPrimitive("String", Type {
points: &Type {
actual: &PrimitiveU32, actual: &PrimitiveU32,
length: 1,
},
kind: TypeKindVariableArray, kind: TypeKindVariableArray,
length: 1,
}) })
// createPrimitive provides a quick way to construct a primitive for the above // createPrimitive provides a quick way to construct a primitive for the above