@@ -426,10 +426,6 @@ func (fc *funcContext) translateExpr(expr ast.Expr) *expression {
426
426
return fc .formatExpr ("$equal(%e, %e, %s)" , e .X , e .Y , fc .typeName (t ))
427
427
case * types.Interface :
428
428
return fc .formatExpr ("$interfaceIsEqual(%s, %s)" , fc .translateImplicitConversion (e .X , t ), fc .translateImplicitConversion (e .Y , t ))
429
- case * types.Pointer :
430
- if _ , ok := u .Elem ().Underlying ().(* types.Array ); ok {
431
- return fc .formatExpr ("$equal(%s, %s, %s)" , fc .translateImplicitConversion (e .X , t ), fc .translateImplicitConversion (e .Y , t ), fc .typeName (u .Elem ()))
432
- }
433
429
case * types.Basic :
434
430
if isBoolean (u ) {
435
431
if b , ok := analysis .BoolValue (e .X , fc .pkgCtx .Info .Info ); ok && b {
@@ -1031,7 +1027,7 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
1031
1027
case t .Kind () == types .UnsafePointer :
1032
1028
if unary , isUnary := expr .(* ast.UnaryExpr ); isUnary && unary .Op == token .AND {
1033
1029
if indexExpr , isIndexExpr := unary .X .(* ast.IndexExpr ); isIndexExpr {
1034
- return fc .formatExpr ("$sliceToArray (%s)" , fc .translateConversionToSlice (indexExpr .X , types .NewSlice (types .Typ [types .Uint8 ])))
1030
+ return fc .formatExpr ("$sliceToNativeArray (%s)" , fc .translateConversionToSlice (indexExpr .X , types .NewSlice (types .Typ [types .Uint8 ])))
1035
1031
}
1036
1032
if ident , isIdent := unary .X .(* ast.Ident ); isIdent && ident .Name == "_zero" {
1037
1033
return fc .formatExpr ("new Uint8Array(0)" )
@@ -1075,8 +1071,14 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
1075
1071
break
1076
1072
}
1077
1073
1078
- switch u := t .Elem ().Underlying ().(type ) {
1074
+ switch ptrElType := t .Elem ().Underlying ().(type ) {
1079
1075
case * types.Array : // (*[N]T)(expr) — converting expr to a pointer to an array.
1076
+ if _ , ok := exprType .Underlying ().(* types.Slice ); ok {
1077
+ // GopherJS interprets pointer to an array as the array object itself
1078
+ // due to its reference semantics, so the bellow coversion is correct.
1079
+ return fc .formatExpr ("$sliceToGoArray(%e, %s)" , expr , fc .typeName (t ))
1080
+ }
1081
+ // TODO(nevkontakte): Is this just for aliased types (e.g. `type a [4]byte`)?
1080
1082
return fc .translateExpr (expr )
1081
1083
case * types.Struct : // (*StructT)(expr) — converting expr to a pointer to a struct.
1082
1084
if fc .pkgCtx .Pkg .Path () == "syscall" && types .Identical (exprType , types .Typ [types .UnsafePointer ]) {
@@ -1086,7 +1088,7 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
1086
1088
// indeed pointing at a byte array.
1087
1089
array := fc .newVariable ("_array" )
1088
1090
target := fc .newVariable ("_struct" )
1089
- return fc .formatExpr ("(%s = %e, %s = %e, %s, %s)" , array , expr , target , fc .zeroValue (t .Elem ()), fc .loadStruct (array , target , u ), target )
1091
+ return fc .formatExpr ("(%s = %e, %s = %e, %s, %s)" , array , expr , target , fc .zeroValue (t .Elem ()), fc .loadStruct (array , target , ptrElType ), target )
1090
1092
}
1091
1093
// Convert between structs of different types but identical layouts,
1092
1094
// for example:
@@ -1152,7 +1154,7 @@ func (fc *funcContext) translateImplicitConversion(expr ast.Expr, desiredType ty
1152
1154
1153
1155
switch desiredType .Underlying ().(type ) {
1154
1156
case * types.Slice :
1155
- return fc .formatExpr ("$subslice(new %1s(%2e.$array) , %2e.$offset, %2e.$offset + %2e.$length )" , fc .typeName (desiredType ), expr )
1157
+ return fc .formatExpr ("$convertSliceType(%1e , %2s )" , expr , fc .typeName (desiredType ))
1156
1158
1157
1159
case * types.Interface :
1158
1160
if typesutil .IsJsObject (exprType ) {
0 commit comments