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

Extend subtyping rule for restricted type #1480

Merged
merged 4 commits into from
Mar 7, 2022

Conversation

turbolent
Copy link
Member

@turbolent turbolent commented Mar 4, 2022

Closes #1479

Description

When checking T <: U{Vs}, we currently require T == U, assuming both are composite values.
However, the latter may actually be a type requirement.

Extend the subtyping check and require T <: U.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@turbolent turbolent self-assigned this Mar 4, 2022
@turbolent turbolent changed the title Fix Fix value transfer type check Mar 4, 2022
@turbolent
Copy link
Member Author

Added another test case which shows that this is not just a problem for references, but an issue with composite dynamic type and restricted static type.

@turbolent
Copy link
Member Author

Added yet another check which shows that this is actually a limitation of the type checker. The dynamic subtype check in the interpreter relies on this check to succeed

@turbolent turbolent marked this pull request as ready for review March 4, 2022 23:40
@turbolent turbolent requested a review from SupunS as a code owner March 4, 2022 23:40
require.ErrorAs(t, err, &interpreter.ValueTransferTypeError{})
})

t.Run("contract and restricted type", func(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests passed the type checking (correctly) and only failed at run-time due to the defensive value transfer check, which in addition to the static check, also checks subtyping for the underlying value.

@codecov-commenter
Copy link

Codecov Report

Merging #1480 (29157dc) into v0.23 (bc4ef3f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##            v0.23    #1480   +/-   ##
=======================================
  Coverage   75.98%   75.98%           
=======================================
  Files         283      283           
  Lines       36993    36993           
=======================================
+ Hits        28108    28109    +1     
+ Misses       7612     7611    -1     
  Partials     1273     1273           
Flag Coverage Δ
unittests 75.98% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
runtime/sema/type.go 87.78% <100.00%> (ø)
runtime/sema/simple_type.go 96.29% <0.00%> (+3.70%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc4ef3f...29157dc. Read the comment docs.

@turbolent turbolent merged commit 6e0c5bf into v0.23 Mar 7, 2022
@turbolent turbolent deleted the bastian/1479-value-transfer-type-check-bug branch March 7, 2022 22:54
@turbolent turbolent changed the title Fix value transfer type check Extend subtyping rule for restricted type Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants