mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 18:53:29 +00:00
compiler: fix nil constant interface
A nil interface has no dynamic type (or: nil dynamic type). Don't try to use the static type as the dynamic type, because these are different.
This commit is contained in:
+3
-9
@@ -2279,16 +2279,10 @@ func (c *Compiler) parseConst(expr *ssa.Const) (llvm.Value, error) {
|
|||||||
if expr.Value != nil {
|
if expr.Value != nil {
|
||||||
return llvm.Value{}, errors.New("non-nil interface constant")
|
return llvm.Value{}, errors.New("non-nil interface constant")
|
||||||
}
|
}
|
||||||
itfTypeNum, ok := c.ir.TypeNum(expr.Type())
|
// Create a generic nil interface with no dynamic type (typecode=0).
|
||||||
if itfTypeNum >= 1<<16 {
|
|
||||||
return llvm.Value{}, errors.New("interface typecodes do not fit in a 16-bit integer")
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
panic("interface number is unknown")
|
|
||||||
}
|
|
||||||
fields := []llvm.Value{
|
fields := []llvm.Value{
|
||||||
llvm.ConstInt(llvm.Int16Type(), uint64(itfTypeNum), false),
|
llvm.ConstInt(llvm.Int16Type(), 0, false),
|
||||||
llvm.Undef(c.i8ptrType),
|
llvm.ConstPointerNull(c.i8ptrType),
|
||||||
}
|
}
|
||||||
itf := llvm.ConstNamedStruct(c.mod.GetTypeByName("runtime._interface"), fields)
|
itf := llvm.ConstNamedStruct(c.mod.GetTypeByName("runtime._interface"), fields)
|
||||||
return itf, nil
|
return itf, nil
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func (p *Program) AnalyseCallgraph() {
|
|||||||
// Find all types that are put in an interface.
|
// Find all types that are put in an interface.
|
||||||
func (p *Program) AnalyseInterfaceConversions() {
|
func (p *Program) AnalyseInterfaceConversions() {
|
||||||
// Clear, if AnalyseTypes has been called before.
|
// Clear, if AnalyseTypes has been called before.
|
||||||
p.typesWithoutMethods = map[string]int{"interface{}": 0, "error": 1}
|
p.typesWithoutMethods = map[string]int{"nil": 0}
|
||||||
p.typesWithMethods = map[string]*InterfaceType{}
|
p.typesWithMethods = map[string]*InterfaceType{}
|
||||||
|
|
||||||
for _, f := range p.Functions {
|
for _, f := range p.Functions {
|
||||||
|
|||||||
Reference in New Issue
Block a user