Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Conform to Hashable#51

Merged
minacle merged 1 commit intoFlight-School:masterfrom
aymanbagabas:conform-hashable
May 29, 2021
Merged

Conform to Hashable#51
minacle merged 1 commit intoFlight-School:masterfrom
aymanbagabas:conform-hashable

Conversation

@aymanbagabas
Copy link
Contributor

Fixes: #45

@aymanbagabas aymanbagabas force-pushed the conform-hashable branch 2 times, most recently from 9498dd9 to 750cf89 Compare April 8, 2021 15:35
@aymanbagabas aymanbagabas changed the title Conform AnyCodable to Hashable Conform to Hashable Apr 8, 2021
@minacle
Copy link
Collaborator

minacle commented Apr 24, 2021

How about if the value is Codable but not Hashable? These hash value must not equal to others and themselves.

@4brunu
Copy link
Contributor

4brunu commented May 18, 2021

Looking forward to see this PR merged.
If I can somehow help, please let me know 🙂

@aymanbagabas
Copy link
Contributor Author

How about if the value is Codable but not Hashable? These hash value must not equal to others and themselves.

This is not possible. If the value is Codable, then it's Hashable. AnyDecodable and AnyEncodable throw when the value is not Codable, meaning it won't reach the default case when encoding or decoding a value.

https://github.com/Flight-School/AnyCodable/blob/master/Sources/AnyCodable/AnyDecodable.swift#L74-L76
https://github.com/Flight-School/AnyCodable/blob/master/Sources/AnyCodable/AnyEncodable.swift#L101-L104

@minacle
Copy link
Collaborator

minacle commented May 25, 2021

This is not possible. If the value is Codable, then it's Hashable. AnyDecodable and AnyEncodable throw when the value is not Codable, meaning it won't reach the default case when encoding or decoding a value.

You are right. AnyEncodable, AnyDecodable and AnyCodable are implicitly require that values conform to Hashable currently. I am approving it. Let us see test results.

@minacle minacle self-requested a review May 25, 2021 12:12
@4brunu
Copy link
Contributor

4brunu commented May 25, 2021

Sorry to bother, but did the CI started?
I'm asking because I see the message:

1 workflow awaiting approval
First-time contributors need a maintainer to approve running workflows. Learn more.

@minacle
Copy link
Collaborator

minacle commented May 27, 2021

I got 500. I think that @mattt can approve and run.

See below.

@minacle minacle assigned mattt and unassigned mattt May 27, 2021
@minacle
Copy link
Collaborator

minacle commented May 29, 2021

I ran tests per versions on my machine and every case passed. Merging.


Swift 5.1.5

Test Suite 'All tests' started at 2021-05-29 19:29:52.988
Test Suite 'debug.xctest' started at 2021-05-29 19:29:53.035
Test Suite 'AnyCodableTests' started at 2021-05-29 19:29:53.035
Test Case 'AnyCodableTests.testJSONDecoding' started at 2021-05-29 19:29:53.036
Test Case 'AnyCodableTests.testJSONDecoding' passed (0.025 seconds)
Test Case 'AnyCodableTests.testJSONEncoding' started at 2021-05-29 19:29:53.062
Test Case 'AnyCodableTests.testJSONEncoding' passed (0.012 seconds)
Test Suite 'AnyCodableTests' passed at 2021-05-29 19:29:53.073
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.037 (0.037) seconds
Test Suite 'AnyDecodableTests' started at 2021-05-29 19:29:53.074
Test Case 'AnyDecodableTests.testJSONDecoding' started at 2021-05-29 19:29:53.074
Test Case 'AnyDecodableTests.testJSONDecoding' passed (0.005 seconds)
Test Suite 'AnyDecodableTests' passed at 2021-05-29 19:29:53.079
	 Executed 1 test, with 0 failures (0 unexpected) in 0.005 (0.005) seconds
Test Suite 'AnyEncodableTests' started at 2021-05-29 19:29:53.079
Test Case 'AnyEncodableTests.testEncodeNSNumber' started at 2021-05-29 19:29:53.079
Test Case 'AnyEncodableTests.testEncodeNSNumber' passed (0.004 seconds)
Test Case 'AnyEncodableTests.testJSONEncoding' started at 2021-05-29 19:29:53.084
Test Case 'AnyEncodableTests.testJSONEncoding' passed (0.004 seconds)
Test Case 'AnyEncodableTests.testStringInterpolationEncoding' started at 2021-05-29 19:29:53.087
Test Case 'AnyEncodableTests.testStringInterpolationEncoding' passed (0.003 seconds)
Test Suite 'AnyEncodableTests' passed at 2021-05-29 19:29:53.090
	 Executed 3 tests, with 0 failures (0 unexpected) in 0.01 (0.01) seconds
Test Suite 'debug.xctest' passed at 2021-05-29 19:29:53.090
	 Executed 6 tests, with 0 failures (0 unexpected) in 0.052 (0.052) seconds
Test Suite 'All tests' passed at 2021-05-29 19:29:53.090
	 Executed 6 tests, with 0 failures (0 unexpected) in 0.052 (0.052) seconds

Swift 5.2.5

Test Suite 'All tests' started at 2021-05-29 19:35:06.082
Test Suite 'debug.xctest' started at 2021-05-29 19:35:06.128
Test Suite 'AnyCodableTests' started at 2021-05-29 19:35:06.128
Test Case 'AnyCodableTests.testJSONDecoding' started at 2021-05-29 19:35:06.128
Test Case 'AnyCodableTests.testJSONDecoding' passed (0.024 seconds)
Test Case 'AnyCodableTests.testJSONEncoding' started at 2021-05-29 19:35:06.153
Test Case 'AnyCodableTests.testJSONEncoding' passed (0.011 seconds)
Test Suite 'AnyCodableTests' passed at 2021-05-29 19:35:06.165
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.035 (0.035) seconds
Test Suite 'AnyDecodableTests' started at 2021-05-29 19:35:06.165
Test Case 'AnyDecodableTests.testJSONDecoding' started at 2021-05-29 19:35:06.165
Test Case 'AnyDecodableTests.testJSONDecoding' passed (0.004 seconds)
Test Suite 'AnyDecodableTests' passed at 2021-05-29 19:35:06.170
	 Executed 1 test, with 0 failures (0 unexpected) in 0.004 (0.004) seconds
Test Suite 'AnyEncodableTests' started at 2021-05-29 19:35:06.170
Test Case 'AnyEncodableTests.testEncodeNSNumber' started at 2021-05-29 19:35:06.170
Test Case 'AnyEncodableTests.testEncodeNSNumber' passed (0.003 seconds)
Test Case 'AnyEncodableTests.testJSONEncoding' started at 2021-05-29 19:35:06.173
Test Case 'AnyEncodableTests.testJSONEncoding' passed (0.003 seconds)
Test Case 'AnyEncodableTests.testStringInterpolationEncoding' started at 2021-05-29 19:35:06.176
Test Case 'AnyEncodableTests.testStringInterpolationEncoding' passed (0.002 seconds)
Test Suite 'AnyEncodableTests' passed at 2021-05-29 19:35:06.178
	 Executed 3 tests, with 0 failures (0 unexpected) in 0.008 (0.008) seconds
Test Suite 'debug.xctest' passed at 2021-05-29 19:35:06.178
	 Executed 6 tests, with 0 failures (0 unexpected) in 0.048 (0.048) seconds
Test Suite 'All tests' passed at 2021-05-29 19:35:06.178
	 Executed 6 tests, with 0 failures (0 unexpected) in 0.048 (0.048) seconds

Swift 5.3.3

Test Suite 'All tests' started at 2021-05-29 19:39:25.727
Test Suite 'debug.xctest' started at 2021-05-29 19:39:25.764
Test Suite 'AnyCodableTests' started at 2021-05-29 19:39:25.765
Test Case 'AnyCodableTests.testJSONDecoding' started at 2021-05-29 19:39:25.765
Test Case 'AnyCodableTests.testJSONDecoding' passed (0.022 seconds)
Test Case 'AnyCodableTests.testJSONEncoding' started at 2021-05-29 19:39:25.788
Test Case 'AnyCodableTests.testJSONEncoding' passed (0.011 seconds)
Test Suite 'AnyCodableTests' passed at 2021-05-29 19:39:25.799
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.033 (0.033) seconds
Test Suite 'AnyDecodableTests' started at 2021-05-29 19:39:25.800
Test Case 'AnyDecodableTests.testJSONDecoding' started at 2021-05-29 19:39:25.800
Test Case 'AnyDecodableTests.testJSONDecoding' passed (0.005 seconds)
Test Suite 'AnyDecodableTests' passed at 2021-05-29 19:39:25.805
	 Executed 1 test, with 0 failures (0 unexpected) in 0.005 (0.005) seconds
Test Suite 'AnyEncodableTests' started at 2021-05-29 19:39:25.805
Test Case 'AnyEncodableTests.testEncodeNSNumber' started at 2021-05-29 19:39:25.805
Test Case 'AnyEncodableTests.testEncodeNSNumber' passed (0.004 seconds)
Test Case 'AnyEncodableTests.testJSONEncoding' started at 2021-05-29 19:39:25.809
Test Case 'AnyEncodableTests.testJSONEncoding' passed (0.004 seconds)
Test Case 'AnyEncodableTests.testStringInterpolationEncoding' started at 2021-05-29 19:39:25.812
Test Case 'AnyEncodableTests.testStringInterpolationEncoding' passed (0.003 seconds)
Test Suite 'AnyEncodableTests' passed at 2021-05-29 19:39:25.815
	 Executed 3 tests, with 0 failures (0 unexpected) in 0.01 (0.01) seconds
Test Suite 'debug.xctest' passed at 2021-05-29 19:39:25.815
	 Executed 6 tests, with 0 failures (0 unexpected) in 0.048 (0.048) seconds
Test Suite 'All tests' passed at 2021-05-29 19:39:25.815
	 Executed 6 tests, with 0 failures (0 unexpected) in 0.048 (0.048) seconds

Swift 5.4.1

Test Suite 'All tests' started at 2021-05-29 19:42:18.164
Test Suite 'debug.xctest' started at 2021-05-29 19:42:18.201
Test Suite 'AnyCodableTests' started at 2021-05-29 19:42:18.202
Test Case 'AnyCodableTests.testJSONDecoding' started at 2021-05-29 19:42:18.202
Test Case 'AnyCodableTests.testJSONDecoding' passed (0.024 seconds)
Test Case 'AnyCodableTests.testJSONEncoding' started at 2021-05-29 19:42:18.227
Test Case 'AnyCodableTests.testJSONEncoding' passed (0.012 seconds)
Test Suite 'AnyCodableTests' passed at 2021-05-29 19:42:18.239
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.036 (0.036) seconds
Test Suite 'AnyDecodableTests' started at 2021-05-29 19:42:18.240
Test Case 'AnyDecodableTests.testJSONDecoding' started at 2021-05-29 19:42:18.240
Test Case 'AnyDecodableTests.testJSONDecoding' passed (0.003 seconds)
Test Suite 'AnyDecodableTests' passed at 2021-05-29 19:42:18.243
	 Executed 1 test, with 0 failures (0 unexpected) in 0.003 (0.003) seconds
Test Suite 'AnyEncodableTests' started at 2021-05-29 19:42:18.243
Test Case 'AnyEncodableTests.testEncodeNSNumber' started at 2021-05-29 19:42:18.243
Test Case 'AnyEncodableTests.testEncodeNSNumber' passed (0.003 seconds)
Test Case 'AnyEncodableTests.testJSONEncoding' started at 2021-05-29 19:42:18.246
Test Case 'AnyEncodableTests.testJSONEncoding' passed (0.003 seconds)
Test Case 'AnyEncodableTests.testStringInterpolationEncoding' started at 2021-05-29 19:42:18.249
Test Case 'AnyEncodableTests.testStringInterpolationEncoding' passed (0.002 seconds)
Test Suite 'AnyEncodableTests' passed at 2021-05-29 19:42:18.252
	 Executed 3 tests, with 0 failures (0 unexpected) in 0.008 (0.008) seconds
Test Suite 'debug.xctest' passed at 2021-05-29 19:42:18.252
	 Executed 6 tests, with 0 failures (0 unexpected) in 0.048 (0.048) seconds
Test Suite 'All tests' passed at 2021-05-29 19:42:18.252
	 Executed 6 tests, with 0 failures (0 unexpected) in 0.048 (0.048) seconds

@minacle minacle merged commit fd1052d into Flight-School:master May 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

How to convert AnyCodable to Hashable

4 participants

Comments