Skip to content

Commit d2d8a01

Browse files
authored
Merge pull request #193 from jmattheis/underlying-sigsegv
fix: SIGSEGV with enabled useUnderlyingTypeMethods
2 parents 08fffb5 + 877d0c4 commit d2d8a01

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

builder/underlying.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (u *UseUnderlyingTypeMethods) Assign(gen Generator, ctx *MethodContext, ass
6868

6969
func findUnderlyingExtendMapping(ctx *MethodContext, source, target *xtype.Type) (underlyingSource, underlyingTarget bool) {
7070
if source.Named {
71-
if ctx.HasMethod(ctx, source.NamedType.Underlying(), target.NamedType) {
71+
if ctx.HasMethod(ctx, source.NamedType.Underlying(), target.T) {
7272
return true, false
7373
}
7474

@@ -77,7 +77,7 @@ func findUnderlyingExtendMapping(ctx *MethodContext, source, target *xtype.Type)
7777
}
7878
}
7979

80-
if target.Named && ctx.HasMethod(ctx, source.NamedType, target.NamedType.Underlying()) {
80+
if target.Named && ctx.HasMethod(ctx, source.T, target.NamedType.Underlying()) {
8181
return false, true
8282
}
8383

docs/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import GH from './GH.vue';
88

99
- Allow specifying `goverter:` settings without leading space e.g.
1010
`//goverter:converter` <GH issue="190" pr="191"/>
11+
- Fix SEGSEGV with enabled
12+
[`useUnderlyingTypeMethods`](reference/useUnderlyingTypeMethods.md)
13+
<GH issue="192" pr="193"/>
1114

1215
## v1.8.0
1316

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
input:
2+
input.go: |
3+
package underlying
4+
5+
// goverter:converter
6+
// goverter:extend IntToString
7+
// goverter:useUnderlyingTypeMethods
8+
type C1 interface { C(source X[IntID]) X[StringID] }
9+
10+
// goverter:converter
11+
// goverter:extend IntToString
12+
// goverter:useUnderlyingTypeMethods
13+
type C2 interface { C(source X[IntID]) X[string] }
14+
15+
// goverter:converter
16+
// goverter:extend IntToString
17+
// goverter:useUnderlyingTypeMethods
18+
type C3 interface { C(source X[int]) X[string] }
19+
20+
// goverter:converter
21+
// goverter:extend IntToString
22+
// goverter:useUnderlyingTypeMethods
23+
type C4 interface { C(source X[int]) X[StringID] }
24+
25+
func IntToString(s int) string { return "" }
26+
27+
type IntID int
28+
type StringID string
29+
30+
type X[T any] struct { T T }
31+
success:
32+
- generated/generated.go: |
33+
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
34+
35+
package generated
36+
37+
import execution "github.com/jmattheis/goverter/execution"
38+
39+
type C1Impl struct{}
40+
41+
func (c *C1Impl) C(source execution.X[execution.IntID]) execution.X[execution.StringID] {
42+
var underlyingX execution.X[execution.StringID]
43+
underlyingX.T = execution.StringID(execution.IntToString(int(source.T)))
44+
return underlyingX
45+
}
46+
47+
type C2Impl struct{}
48+
49+
func (c *C2Impl) C(source execution.X[execution.IntID]) execution.X[string] {
50+
var underlyingX execution.X[string]
51+
underlyingX.T = execution.IntToString(int(source.T))
52+
return underlyingX
53+
}
54+
55+
type C3Impl struct{}
56+
57+
func (c *C3Impl) C(source execution.X[int]) execution.X[string] {
58+
var underlyingX execution.X[string]
59+
underlyingX.T = execution.IntToString(source.T)
60+
return underlyingX
61+
}
62+
63+
type C4Impl struct{}
64+
65+
func (c *C4Impl) C(source execution.X[int]) execution.X[execution.StringID] {
66+
var underlyingX execution.X[execution.StringID]
67+
underlyingX.T = execution.StringID(execution.IntToString(source.T))
68+
return underlyingX
69+
}

0 commit comments

Comments
 (0)