Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to build with latest exp sort #985

Closed
GreyXor opened this issue Jul 25, 2023 · 10 comments · Fixed by #987
Closed

Failed to build with latest exp sort #985

GreyXor opened this issue Jul 25, 2023 · 10 comments · Fixed by #987
Labels
bug Something isn't working

Comments

@GreyXor
Copy link

GreyXor commented Jul 25, 2023

What version of ogen are you using?

1.71.1

Can this issue be reproduced with the latest version?

Yes

What did you do?

Build ogen with latest exp
related history : https://cs.opensource.google/go/x/exp/+/master:slices/sort.go;bpv=1;bpt=0;drc=302865e7556b4ae5de27248ce625d443ef4ad3ed;dlc=864b3d6c5c2c5ebc4e14047a4975d8acde58bca6

What did you expect to see?

build without error

What did you see instead?

 github.com/ogen-go/ogen/internal/location
/home/greyxor/go/pkg/mod/github.com/ogen-go/[email protected]/internal/location/error.go:162:34: type func(a Report, b Report) bool of func(a, b Report) bool {…} does not match inferred type func(a Report, b Report) int for func(a E, b E) int

/home/greyxor/go/pkg/mod/github.com/ogen-go/[email protected]/internal/location/error.go:211:32: type func(a reportChunk, b reportChunk) bool of func(a, b reportChunk) bool {…} does not match inferred type func(a reportChunk, b reportChunk) int for func(a E, b E) int
@GreyXor GreyXor added the bug Something isn't working label Jul 25, 2023
@docktermj
Copy link

I am seeing this same error in 1.71.1. To reproduce what I'm seeing

git clone [email protected]:Senzing/go-rest-api-service.git
cd go-rest-api-service
git checkout 934f407
make test

The documentation on how I generated the files is at https://github.com/Senzing/go-rest-api-service/blob/934f407beb27f54c72cf8698e0ada59fc43edee5/docs/development.md

@tdakkota
Copy link
Member

It seems API of golang.org/x/exp package changed, try to downgrade version.

ogen requires:

ogen/go.mod

Line 22 in 2f8b4fa

golang.org/x/exp v0.0.0-20230321023759-10a507213a29

@docktermj
Copy link

@ernado With 0.72.0 I'm getting these new errors:

=== RUN   TestAddRecordReq_Examples/Test1
    oas_test_examples_gen_test.go:176: 
        	Error Trace:	/home/senzing/senzing.git/go-rest-api-service/senzingrestapi/oas_test_examples_gen_test.go:176
        	Error:      	Received unexpected error:
        	            	decode AddRecordReq:
        	            	    github.com/senzing/go-rest-api-service/senzingrestapi.(*AddRecordReq).Decode
        	            	        /home/senzing/senzing.git/go-rest-api-service/senzingrestapi/oas_json_gen.go:339
        	            	  - "{" expected:
        	            	    github.com/go-faster/jx.(*Decoder).ObjBytes
        	            	        /home/senzing/go/pkg/mod/github.com/go-faster/[email protected]/dec_obj.go:12
        	            	  - unexpected byte 34 '"' at 0
        	Test:       	TestAddRecordReq_Examples/Test1
        	Messages:   	Input: "{\n  \"NAMES\": [\n    {\n      \"NAME_FIRST\": \"JANE\",\n      \"NAME_LAST\": \"SCHMOE\"\n    }\n  ],\n  \"PHONE_NUMBERS\": [\n    {\n      \"PHONE_NUMBER\": \"559-555-1212\"\n    }\n  ],\n  \"ADDRESSES\": [\n    {\n      \"ADDR_LINE1\": \"653 STATE ROUTE 7\",\n      \"ADDR_CITY\": \"FRESNO\",\n      \"ADDR_STATE\": \"CA\",\n      \"ADDR_POSTAL_CODE\": \"55073-1234\"\n    }\n  ]\n}"

@docktermj
Copy link

The generated testcase:

func TestAddRecordReq_Examples(t *testing.T) {

	for i, tc := range []struct {
		Input string
	}{
		{Input: "\"{\\n  \\\"NAMES\\\": [\\n    {\\n      \\\"NAME_FIRST\\\": \\\"JANE\\\",\\n      \\\"NAME_LAST\\\": \\\"SCHMOE\\\"\\n    }\\n  ],\\n  \\\"PHONE_NUMBERS\\\": [\\n    {\\n      \\\"PHONE_NUMBER\\\": \\\"559-555-1212\\\"\\n    }\\n  ],\\n  \\\"ADDRESSES\\\": [\\n    {\\n      \\\"ADDR_LINE1\\\": \\\"653 STATE ROUTE 7\\\",\\n      \\\"ADDR_CITY\\\": \\\"FRESNO\\\",\\n      \\\"ADDR_STATE\\\": \\\"CA\\\",\\n      \\\"ADDR_POSTAL_CODE\\\": \\\"55073-1234\\\"\\n    }\\n  ]\\n}\""},
		{Input: "\"{\\n  \\\"NAMES\\\": [\\n    {\\n      \\\"NAME_TYPE\\\": \\\"PRIMARY\\\",\\n      \\\"NAME_FIRST\\\": \\\"JANE\\\",\\n      \\\"NAME_LAST\\\": \\\"SCHMOE\\\"\\n    },\\n    {\\n      \\\"NAME_TYPE\\\": \\\"MAIDEN\\\",\\n      \\\"NAME_FIRST\\\": \\\"JANE\\\",\\n      \\\"NAME_LAST\\\": \\\"SMITH\\\"\\n    }\\n  ],\\n  \\\"PHONE_NUMBERS\\\": [\\n    {\\n      \\\"PHONE_TYPE\\\": \\\"HOME\\\",\\n      \\\"PHONE_NUMBER\\\": \\\"559-555-1212\\\"\\n    },\\n    {\\n      \\\"PHONE_TYPE\\\": \\\"WORK\\\",\\n      \\\"PHONE_NUMBER\\\": \\\"559-555-1414\\\"\\n    }\\n  ],\\n  \\\"ADDRESSES\\\": [\\n    {\\n      \\\"ADDR_TYPE\\\": \\\"HOME\\\",\\n      \\\"ADDR_LINE1\\\": \\\"653 STATE ROUTE 7\\\",\\n      \\\"ADDR_CITY\\\": \\\"FRESNO\\\",\\n      \\\"ADDR_STATE\\\": \\\"CA\\\",\\n      \\\"ADDR_POSTAL_CODE\\\": \\\"55073-1234\\\"\\n    },\\n    {\\n      \\\"ADDR_TYPE\\\": \\\"WORK\\\",\\n      \\\"ADDR_LINE1\\\": \\\"701 E MAIN STREET\\\",\\n      \\\"ADDR_CITY\\\": \\\"FOWLER\\\",\\n      \\\"ADDR_STATE\\\": \\\"CA\\\",\\n      \\\"ADDR_POSTAL_CODE\\\": \\\"93625\\\"\\n    }\\n  ]\\n}\""},
		{Input: "\"{\\n  \\\"NAME_FIRST\\\": \\\"JANE\\\",\\n  \\\"NAME_LAST\\\": \\\"SCHMOE\\\",\\n  \\\"HOME_PHONE_NUMBER\\\": \\\"559-555-1212\\\",\\n  \\\"WORK_PHONE_NUMBER\\\": \\\"559-555-1414\\\",\\n  \\\"HOME_ADDR_LINE1\\\": \\\"653 STATE ROUTE 7\\\",\\n  \\\"HOME_ADDR_CITY\\\": \\\"FRESNO\\\",\\n  \\\"HOME_ADDR_STATE\\\": \\\"CA\\\",\\n  \\\"HOME_ADDR_POSTAL_CODE\\\": \\\"55073-1234\\\"\\n  \\\"WORK_ADDR_LINE1\\\": \\\"701 E MAIN STREET\\\",\\n  \\\"WORK_ADDR_CITY\\\": \\\"FOWLER\\\",\\n  \\\"WORK_ADDR_STATE\\\": \\\"CA\\\",\\n  \\\"WORK_ADDR_POSTAL_CODE\\\": \\\"93625\\\"\\n}\""},
		{Input: "\"{\\n  \\\"NAME_FIRST\\\": \\\"JANE\\\",\\n  \\\"NAME_LAST\\\": \\\"SCHMOE\\\",\\n  \\\"PHONE_NUMBER\\\": \\\"559-555-1212\\\",\\n  \\\"ADDR_LINE1\\\": \\\"653 STATE ROUTE 7\\\",\\n  \\\"ADDR_CITY\\\": \\\"FRESNO\\\",\\n  \\\"ADDR_STATE\\\": \\\"CA\\\",\\n  \\\"ADDR_POSTAL_CODE\\\": \\\"55073-1234\\\"\\n}\""},
	} {
		tc := tc
		t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
			var typ AddRecordReq
			typ = make(AddRecordReq)

			if err := typ.Decode(jx.DecodeStr(tc.Input)); err != nil {
				if validateErr, ok := errors.Into[*validate.Error](err); ok {
					t.Skipf("Validation error: %v", validateErr)
					return
				}
				require.NoErrorf(t, err, "Input: %s", tc.Input)
			}

			e := jx.Encoder{}
			typ.Encode(&e)
			require.True(t, std.Valid(e.Bytes()), "Encoded: %s", e.Bytes())

			var typ2 AddRecordReq
			typ2 = make(AddRecordReq)
			require.NoError(t, typ2.Decode(jx.DecodeBytes(e.Bytes())))
		})
	}
}

@docktermj
Copy link

To recreate:

git clone [email protected]:Senzing/go-rest-api-service.git
cd go-rest-api-service
git checkout 1183ad6
make test

@docktermj
Copy link

@tdakkota , @GreyXor , @ernado Let me know if you'd like me to open a new issue.

@tdakkota
Copy link
Member

@docktermj It's a generated test for spec examples.

Probably somewhere in spec example set as a string literal, not an object.

@ernado
Copy link
Member

ernado commented Jul 26, 2023

@docktermj
please try generating without --generate-tests flag.

@docktermj
Copy link

@ernado That does fix it (because the test isn't there). Am I exposing my code to issues without those tests? That is, will the code that uses the generated code have the same issues that the test did?

@ernado
Copy link
Member

ernado commented Jul 27, 2023

That is, will the code that uses the generated code have the same issues that the test did?

I think that it is test-only issue and you can create a new isolated issue for this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants