compiler: don't crash when encountering types.Invalid

This commit fixes a crash when trying to compile the following (invalid)
code:

    package main

    import "unsafe"

    func main() {
    }

    type Foo struct {
       x DoesNotExist
    }

    const foo = unsafe.Sizeof(Foo{})

This commit fixes this situation. The result is a regular error message,
indicating that DoesNotExist is not defined.
Этот коммит содержится в:
Ayke van Laethem 2019-12-26 02:25:44 +01:00 коммит произвёл Ron Evans
родитель a5a90a57b9
коммит a4fa41b49d

Просмотреть файл

@ -110,6 +110,9 @@ func (s *StdSizes) Sizeof(T types.Type) int64 {
if k == types.UnsafePointer {
return s.PtrSize
}
if k == types.Invalid {
return 0 // only relevant when there is a type error somewhere
}
panic("unknown basic type: " + t.String())
case *types.Array:
n := t.Len()