mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:11:12 +01:00
Stop allowing impl redeclarations to differ syntactically in where clause (#4850)
Based on [the lastest thinking on #4672](https://github.com/carbon-language/carbon-lang/issues/4672#issuecomment-2606209281) , require a full syntactic match for impl redeclaration, instead of excluding the `where` restriction. This means no updates to the impl witness on redeclaration, and no diagnostics that those updates are consistent. Not included in this PR, but will need to be done in the future: * Support for assigning values to associated constants in the body of the impl definition. This will require moving the checking that non-function associated constants are set from the definition start to definition end. * Identify semantic redeclarations that are not syntactic matches to give a failed redeclaration diagnostic. This should be done once we are already identifying impl declarations with the same type structure in order to require they be identified in an impl_priority/match_first block. * Merging of the functions in `check/impl.cpp` that are now always called together. Also add some test coverage of `where` parsing I developed in PR I've now abandoned because of this new simplification of the impl redeclaration semantics. --------- Co-authored-by: Josh L <josh11b@users.noreply.github.com> Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Josh L
Jon Ross-Perkins
parent
0d0e202ce8
commit
5abe5a3c21
@@ -17,6 +17,13 @@ impl i32 as Interface where .T = () {
|
||||
|
||||
impl bool as Interface where .T = i32;
|
||||
|
||||
impl () as (Interface where .T = {}) {}
|
||||
|
||||
impl {} as (Interface where .T = ()) where .T = ();
|
||||
|
||||
impl f64 as Interface where .T = (type where .Self impls type) {
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: - filename: impl_where.carbon
|
||||
// CHECK:STDOUT: parse_tree: [
|
||||
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
|
||||
@@ -53,5 +60,63 @@ impl bool as Interface where .T = i32;
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 7},
|
||||
// CHECK:STDOUT: {kind: 'ImplDecl', text: ';', subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
|
||||
// CHECK:STDOUT: {kind: 'TupleLiteralStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'TupleLiteral', text: ')', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'TypeImplAs', text: 'as', subtree_size: 3},
|
||||
// CHECK:STDOUT: {kind: 'ParenExprStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Interface'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralStart', text: '{'},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 5},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 8},
|
||||
// CHECK:STDOUT: {kind: 'ParenExpr', text: ')', subtree_size: 10},
|
||||
// CHECK:STDOUT: {kind: 'ImplDefinitionStart', text: '{', subtree_size: 15},
|
||||
// CHECK:STDOUT: {kind: 'ImplDefinition', text: '}', subtree_size: 16},
|
||||
// CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralStart', text: '{'},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'TypeImplAs', text: 'as', subtree_size: 3},
|
||||
// CHECK:STDOUT: {kind: 'ParenExprStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Interface'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'TupleLiteralStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'TupleLiteral', text: ')', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 5},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 8},
|
||||
// CHECK:STDOUT: {kind: 'ParenExpr', text: ')', subtree_size: 10},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'TupleLiteralStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'TupleLiteral', text: ')', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 5},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 17},
|
||||
// CHECK:STDOUT: {kind: 'ImplDecl', text: ';', subtree_size: 22},
|
||||
// CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
|
||||
// CHECK:STDOUT: {kind: 'FloatTypeLiteral', text: 'f64'},
|
||||
// CHECK:STDOUT: {kind: 'TypeImplAs', text: 'as', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Interface'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'ParenExprStart', text: '('},
|
||||
// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
|
||||
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'SelfTypeName', text: 'Self'},
|
||||
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
|
||||
// CHECK:STDOUT: {kind: 'RequirementImpls', text: 'impls', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 7},
|
||||
// CHECK:STDOUT: {kind: 'ParenExpr', text: ')', subtree_size: 9},
|
||||
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 12},
|
||||
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 15},
|
||||
// CHECK:STDOUT: {kind: 'ImplDefinitionStart', text: '{', subtree_size: 19},
|
||||
// CHECK:STDOUT: {kind: 'ImplDefinition', text: '}', subtree_size: 20},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
// CHECK:STDOUT: ]
|
||||
|
||||
Reference in New Issue
Block a user