E4136#
This expression has type that is not a newtype.
In MoonBit, you can access the field of underlying struct of a newtype by using
the dot access operator (.
). However, you cannot access the field of a struct
if it is not wrapped in a newtype.
错误示例#
struct Inner {
value : Int
}
type! ErrorOuter Inner
enum EnumOuter {
Outer(Inner)
}
fn main {
let outer : ErrorOuter = ErrorOuter(Inner::{ value: 1 })
println(outer.value) // Error: This expression has type ErrorOuter, which is a error type type and not a record.
let outer : EnumOuter = Outer(Inner::{ value: 2 })
println(outer.value) // Error: This expression has type EnumOuter, which is a variant type and not a record.
}
建议#
If you want to access the field of the underlying struct, you should wrap the in a newtype:
type Outer Inner
fn main {
let outer : Outer = Inner::{ value: 1 }
println(outer.value)
}