-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Adjust polymorphicInstance()
#14635
Merged
Merged
Adjust polymorphicInstance()
#14635
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9530bec
Tests covering the uses of polymorphic functions and types
cameel f06aed8
Function types in `typeClassFunctions()` do not need `polymorphicInst…
cameel c078827
Type classes currently cannot take type parameters
cameel 0162b8e
Remove TypeInference::unifyGeneralized()
cameel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ibsolidity/syntaxTests/experimental/inference/monomorphic_function_call_type_mismatch.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pragma experimental solidity; | ||
|
||
type T; | ||
type U; | ||
|
||
function f(x: T, y: U) {} | ||
|
||
function run(a: U, b: T) { | ||
f(a, b); | ||
} | ||
// ==== | ||
// EVMVersion: >=constantinople | ||
// ---- | ||
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments. | ||
// TypeError 8456: (106-113): Cannot unify T and U. | ||
// TypeError 8456: (106-113): Cannot unify U and T. |
53 changes: 53 additions & 0 deletions
53
test/libsolidity/syntaxTests/experimental/inference/polymorphic_function_call.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
pragma experimental solidity; | ||
|
||
type T; | ||
type U(A); | ||
|
||
function f(x, y: X, z: U(Y)) {} | ||
|
||
function run(a: T, b: U(T), c: U(U(T))) { | ||
f(a, a, b); | ||
f(b, b, c); | ||
} | ||
// ==== | ||
// EVMVersion: >=constantinople | ||
// compileViaYul: true | ||
// ---- | ||
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments. | ||
// Info 4164: (31-38): Inferred type: T | ||
// Info 4164: (39-49): Inferred type: tfun('u:type, U('u:type)) | ||
// Info 4164: (45-48): Inferred type: 't:type | ||
// Info 4164: (46-47): Inferred type: 't:type | ||
// Info 4164: (51-82): Inferred type: ('x:type, 'y:type, U('ba:type)) -> () | ||
// Info 4164: (61-79): Inferred type: ('x:type, 'y:type, U('ba:type)) | ||
// Info 4164: (62-63): Inferred type: 'x:type | ||
// Info 4164: (65-69): Inferred type: 'y:type | ||
// Info 4164: (68-69): Inferred type: 'y:type | ||
// Info 4164: (71-78): Inferred type: U('ba:type) | ||
// Info 4164: (74-78): Inferred type: U('ba:type) | ||
// Info 4164: (74-75): Inferred type: tfun('ba:type, U('ba:type)) | ||
// Info 4164: (76-77): Inferred type: 'ba:type | ||
// Info 4164: (84-159): Inferred type: (T, U(T), U(U(T))) -> () | ||
// Info 4164: (96-123): Inferred type: (T, U(T), U(U(T))) | ||
// Info 4164: (97-101): Inferred type: T | ||
// Info 4164: (100-101): Inferred type: T | ||
// Info 4164: (103-110): Inferred type: U(T) | ||
// Info 4164: (106-110): Inferred type: U(T) | ||
// Info 4164: (106-107): Inferred type: tfun(T, U(T)) | ||
// Info 4164: (108-109): Inferred type: T | ||
// Info 4164: (112-122): Inferred type: U(U(T)) | ||
// Info 4164: (115-122): Inferred type: U(U(T)) | ||
// Info 4164: (115-116): Inferred type: tfun(U(T), U(U(T))) | ||
// Info 4164: (117-121): Inferred type: U(T) | ||
// Info 4164: (117-118): Inferred type: tfun(T, U(T)) | ||
// Info 4164: (119-120): Inferred type: T | ||
// Info 4164: (130-140): Inferred type: () | ||
// Info 4164: (130-131): Inferred type: (T, T, U(T)) -> () | ||
// Info 4164: (132-133): Inferred type: T | ||
// Info 4164: (135-136): Inferred type: T | ||
// Info 4164: (138-139): Inferred type: U(T) | ||
// Info 4164: (146-156): Inferred type: () | ||
// Info 4164: (146-147): Inferred type: (U(T), U(T), U(U(T))) -> () | ||
// Info 4164: (148-149): Inferred type: U(T) | ||
// Info 4164: (151-152): Inferred type: U(T) | ||
// Info 4164: (154-155): Inferred type: U(U(T)) |
19 changes: 19 additions & 0 deletions
19
...olidity/syntaxTests/experimental/inference/polymorphic_function_call_let_polymorphism.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pragma experimental solidity; | ||
|
||
type T; | ||
type U; | ||
|
||
function f(x) {} | ||
|
||
function run(a: T, b: U) { | ||
// NOTE: The type of f is polymorphic but the inferred type of g is not - this would be | ||
// let-polymorphism, which we decided not to support. | ||
let g = f; | ||
g(a); | ||
g(b); | ||
} | ||
// ==== | ||
// EVMVersion: >=constantinople | ||
// ---- | ||
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments. | ||
// TypeError 8456: (272-276): Cannot unify T and U. |
16 changes: 16 additions & 0 deletions
16
...ibsolidity/syntaxTests/experimental/inference/polymorphic_function_call_type_mismatch.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pragma experimental solidity; | ||
|
||
type T(A); | ||
type U; | ||
type V; | ||
|
||
function f(x: T(U)) {} | ||
|
||
function run(a: T(V)) { | ||
f(a); | ||
} | ||
// ==== | ||
// EVMVersion: >=constantinople | ||
// ---- | ||
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments. | ||
// TypeError 8456: (111-115): Cannot unify U and V. |
47 changes: 47 additions & 0 deletions
47
test/libsolidity/syntaxTests/experimental/inference/polymorphic_type.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
pragma experimental solidity; | ||
|
||
type T(P, Q, R); | ||
type U; | ||
type V; | ||
|
||
class Self: C {} | ||
class Self: D {} | ||
|
||
function run() { | ||
let x: T(U, X, Z: C); | ||
let y: T(V, Y, Z: D); | ||
} | ||
// ==== | ||
// EVMVersion: >=constantinople | ||
// compileViaYul: true | ||
// ---- | ||
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments. | ||
// Info 4164: (31-47): Inferred type: tfun(('ba:type, 'bb:type, 'bc:type), T('ba:type, 'bb:type, 'bc:type)) | ||
// Info 4164: (37-46): Inferred type: ('x:type, 'y:type, 'z:type) | ||
// Info 4164: (38-39): Inferred type: 'x:type | ||
// Info 4164: (41-42): Inferred type: 'y:type | ||
// Info 4164: (44-45): Inferred type: 'z:type | ||
// Info 4164: (48-55): Inferred type: U | ||
// Info 4164: (56-63): Inferred type: V | ||
// Info 4164: (65-81): Inferred type: C | ||
// Info 4164: (71-75): Inferred type: 'be:(type, C) | ||
// Info 4164: (82-98): Inferred type: D | ||
// Info 4164: (88-92): Inferred type: 'bg:(type, D) | ||
// Info 4164: (100-170): Inferred type: () -> () | ||
// Info 4164: (112-114): Inferred type: () | ||
// Info 4164: (125-141): Inferred type: T(U, 'bm:type, 'bo:(type, C)) | ||
// Info 4164: (128-141): Inferred type: T(U, 'bm:type, 'bo:(type, C)) | ||
// Info 4164: (128-129): Inferred type: tfun((U, 'bm:type, 'bo:(type, C)), T(U, 'bm:type, 'bo:(type, C))) | ||
// Info 4164: (130-131): Inferred type: U | ||
// Info 4164: (133-134): Inferred type: 'bm:type | ||
// Info 4164: (136-140): Inferred type: 'bo:(type, C) | ||
// Info 4164: (136-137): Inferred type: 'bo:(type, C) | ||
// Info 4164: (139-140): Inferred type: 'bo:(type, C) | ||
// Info 4164: (151-167): Inferred type: T(V, 'bt:type, 'bv:(type, D)) | ||
// Info 4164: (154-167): Inferred type: T(V, 'bt:type, 'bv:(type, D)) | ||
// Info 4164: (154-155): Inferred type: tfun((V, 'bt:type, 'bv:(type, D)), T(V, 'bt:type, 'bv:(type, D))) | ||
// Info 4164: (156-157): Inferred type: V | ||
// Info 4164: (159-160): Inferred type: 'bt:type | ||
// Info 4164: (162-166): Inferred type: 'bv:(type, D) | ||
// Info 4164: (162-163): Inferred type: 'bv:(type, D) | ||
// Info 4164: (165-166): Inferred type: 'bv:(type, D) |
69 changes: 69 additions & 0 deletions
69
test/libsolidity/syntaxTests/experimental/inference/polymorphic_type_abs_and_rep.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
pragma experimental solidity; | ||
|
||
type uint; | ||
type string; | ||
|
||
type T(A); | ||
type U(B) = T(B); | ||
|
||
function fun() { | ||
let w: U(uint); | ||
let v: T(uint); | ||
U.rep(w); | ||
U.abs(v); | ||
|
||
let s: U(string); | ||
let t: T(string); | ||
U.rep(s); | ||
U.abs(t); | ||
} | ||
// ==== | ||
// EVMVersion: >=constantinople | ||
// compileViaYul: true | ||
// ---- | ||
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments. | ||
// Info 4164: (31-41): Inferred type: uint | ||
// Info 4164: (42-54): Inferred type: string | ||
// Info 4164: (56-66): Inferred type: tfun('v:type, T('v:type)) | ||
// Info 4164: (62-65): Inferred type: 'u:type | ||
// Info 4164: (63-64): Inferred type: 'u:type | ||
// Info 4164: (67-84): Inferred type: tfun('x:type, U('x:type)) | ||
// Info 4164: (73-76): Inferred type: 'w:type | ||
// Info 4164: (74-75): Inferred type: 'w:type | ||
// Info 4164: (79-83): Inferred type: T('w:type) | ||
// Info 4164: (79-80): Inferred type: tfun('w:type, T('w:type)) | ||
// Info 4164: (81-82): Inferred type: 'w:type | ||
// Info 4164: (86-245): Inferred type: () -> () | ||
// Info 4164: (98-100): Inferred type: () | ||
// Info 4164: (111-121): Inferred type: U(uint) | ||
// Info 4164: (114-121): Inferred type: U(uint) | ||
// Info 4164: (114-115): Inferred type: tfun(uint, U(uint)) | ||
// Info 4164: (116-120): Inferred type: uint | ||
// Info 4164: (131-141): Inferred type: T(uint) | ||
// Info 4164: (134-141): Inferred type: T(uint) | ||
// Info 4164: (134-135): Inferred type: tfun(uint, T(uint)) | ||
// Info 4164: (136-140): Inferred type: uint | ||
// Info 4164: (147-155): Inferred type: T('bi:type) | ||
// Info 4164: (147-152): Inferred type: U(uint) -> T('bi:type) | ||
// Info 4164: (147-148): Inferred type: U('bg:type) | ||
// Info 4164: (153-154): Inferred type: U(uint) | ||
// Info 4164: (161-169): Inferred type: U('bm:type) | ||
// Info 4164: (161-166): Inferred type: T(uint) -> U('bm:type) | ||
// Info 4164: (161-162): Inferred type: U('bk:type) | ||
// Info 4164: (167-168): Inferred type: T(uint) | ||
// Info 4164: (180-192): Inferred type: U(string) | ||
// Info 4164: (183-192): Inferred type: U(string) | ||
// Info 4164: (183-184): Inferred type: tfun(string, U(string)) | ||
// Info 4164: (185-191): Inferred type: string | ||
// Info 4164: (202-214): Inferred type: T(string) | ||
// Info 4164: (205-214): Inferred type: T(string) | ||
// Info 4164: (205-206): Inferred type: tfun(string, T(string)) | ||
// Info 4164: (207-213): Inferred type: string | ||
// Info 4164: (220-228): Inferred type: T('bu:type) | ||
// Info 4164: (220-225): Inferred type: U(string) -> T('bu:type) | ||
// Info 4164: (220-221): Inferred type: U('bs:type) | ||
// Info 4164: (226-227): Inferred type: U(string) | ||
// Info 4164: (234-242): Inferred type: U('by:type) | ||
// Info 4164: (234-239): Inferred type: T(string) -> U('by:type) | ||
// Info 4164: (234-235): Inferred type: U('bw:type) | ||
// Info 4164: (240-241): Inferred type: T(string) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, what? That doesn't seem right - shouldn't there be exactly one variable in there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no, this is term context, so the use of the type class name as a special concrete type with its functions attached as members... I hope the distinction will become clearer after the upcoming refactors, we'll see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So fine with merging the PR?