mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Support struct implicit conversions in type-checking (#870)
I should emphasize that I am **completely cheating** here. This PR does not add support for actually _performing_ implicit conversions at run time, because the AST doesn't yet contain the necessary type information. At run time, code like `var p: Point = {.x = 1, .y = 2};` directly initializes the name `p` with the _struct_ value `{.x = 1, .y = 2}`; no object of type `Point` is actually created. I'm only getting away with this because we don't yet have any tests that can tell the difference.
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
parent
a99d882223
commit
bc5a42211b
@@ -7,9 +7,7 @@
|
||||
// RUN: not executable_semantics --trace %s 2>&1 | \
|
||||
// RUN: FileCheck --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: executable_semantics %s
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/class/fail_field_missing.carbon:22: type error in call
|
||||
// CHECK: expected: (x = i32, y = i32)
|
||||
// CHECK: actual: (x = i32)
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/class/fail_field_missing.carbon:20: type error in name binding: '{.x: i32}' is not implicitly convertible to 'class Point'
|
||||
|
||||
package ExecutableSemanticsTest api;
|
||||
|
||||
@@ -19,5 +17,6 @@ class Point {
|
||||
}
|
||||
|
||||
fn main() -> i32 {
|
||||
return Point(.x = 1).x - 1;
|
||||
var p: Point = {.x = 1};
|
||||
return p.x - 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user