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.
Этот коммит содержится в:
родитель
4ed04309a3
коммит
c100e4d67f
2 изменённых файлов: 4 добавлений и 10 удалений
12
compiler.go
12
compiler.go
|
@ -2279,16 +2279,10 @@ func (c *Compiler) parseConst(expr *ssa.Const) (llvm.Value, error) {
|
|||
if expr.Value != nil {
|
||||
return llvm.Value{}, errors.New("non-nil interface constant")
|
||||
}
|
||||
itfTypeNum, ok := c.ir.TypeNum(expr.Type())
|
||||
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")
|
||||
}
|
||||
// Create a generic nil interface with no dynamic type (typecode=0).
|
||||
fields := []llvm.Value{
|
||||
llvm.ConstInt(llvm.Int16Type(), uint64(itfTypeNum), false),
|
||||
llvm.Undef(c.i8ptrType),
|
||||
llvm.ConstInt(llvm.Int16Type(), 0, false),
|
||||
llvm.ConstPointerNull(c.i8ptrType),
|
||||
}
|
||||
itf := llvm.ConstNamedStruct(c.mod.GetTypeByName("runtime._interface"), fields)
|
||||
return itf, nil
|
||||
|
|
|
@ -103,7 +103,7 @@ func (p *Program) AnalyseCallgraph() {
|
|||
// Find all types that are put in an interface.
|
||||
func (p *Program) AnalyseInterfaceConversions() {
|
||||
// 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{}
|
||||
|
||||
for _, f := range p.Functions {
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче