Skip to content

Commit

Permalink
determine and record explicit composite conformances earlier, before …
Browse files Browse the repository at this point in the history
…usage
  • Loading branch information
turbolent committed Sep 29, 2020
1 parent 8ea5185 commit 051091c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
12 changes: 7 additions & 5 deletions runtime/sema/check_composite_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ func (checker *Checker) declareCompositeType(declaration *ast.CompositeDeclarati
variable,
)

// Resolve conformances

conformances := checker.explicitInterfaceConformances(declaration, compositeType)
compositeType.ExplicitInterfaceConformances = conformances

// Register in elaboration

checker.Elaboration.CompositeDeclarationTypes[declaration] = compositeType

// Activate new scope for nested declarations
Expand Down Expand Up @@ -477,11 +484,6 @@ func (checker *Checker) declareCompositeMembersAndValue(

checker.declareCompositeNestedTypes(declaration, kind, false)

// Resolve conformances

conformances := checker.explicitInterfaceConformances(declaration, compositeType)
compositeType.ExplicitInterfaceConformances = conformances

// NOTE: determine initializer parameter types while nested types are in scope,
// and after declaring nested types as the initializer may use nested type in parameters

Expand Down
23 changes: 23 additions & 0 deletions runtime/tests/checker/restriction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,3 +1101,26 @@ func TestCheckRestrictedTypeConformanceOrder(t *testing.T) {
})

}

// https://github.com/onflow/cadence/issues/326
func TestCheckRestrictedConformance(t *testing.T) {

_, err := ParseAndCheck(t, `
contract C {
resource interface RI {
fun get(): &R{RI}
}
resource R: RI {
fun get(): &R{RI} {
return &self as &R{RI}
}
}
}
`)

require.NoError(t, err)
}

0 comments on commit 051091c

Please sign in to comment.