Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 3f902cd

Browse files
committed
fix(designer): specify temporary variable types to prevent type deduction failures
Addresses type errors in generated code that occurred in certain use cases.
1 parent e2fc581 commit 3f902cd

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

tcw3/designer/src/codegen/implgen/initgen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use pathfinding::directed::{
55
strongly_connected_components::strongly_connected_components,
66
topological_sort::topological_sort,
77
};
8+
use quote::ToTokens;
89
use std::{cell::Cell, collections::HashMap, fmt::Write, ops::Range};
910
use try_match::try_match;
1011

@@ -1044,7 +1045,7 @@ pub fn gen_construct(
10441045

10451046
DepNode::Field { item_i } => {
10461047
let field = comp.items[*item_i].field().unwrap();
1047-
write!(out, "let {} = ", var).unwrap();
1048+
write!(out, "let {}: {} = ", var, field.ty.to_token_stream()).unwrap();
10481049

10491050
if field.value.is_none() {
10501051
// Mandatory field - the value is always available
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
designer_impl! { crate::field::bug_type_deduction::Comp }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use tcw3::pal;
2+
comp crate::field::bug_type_deduction::Comp {
3+
const wm: pal::Wm { set; }
4+
5+
// An old implementation of Designer produced implementation code
6+
// that didn't type-check for these fields:
7+
//
8+
// error[E0282]: type annotations needed
9+
// |
10+
// 695 | let __tmp_1 = match () { () => { "a" . into ( ) } };
11+
// | ------- consider giving `__tmp_1` a type
12+
// 696 | let __tmp_2 = match ((&__tmp_1), ) { (_input_0, ) => { _input_0 . len ( ) } };
13+
// | ^^^ cannot infer type
14+
//
15+
const const1: String = "a".into();
16+
const const2: usize = get!(&const1).len();
17+
}

tcw3/designer/tests_impl/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod commit {
1010

1111
mod field {
1212
mod accessors;
13+
mod bug_type_deduction;
1314
mod lifetime_elision;
1415
mod prop;
1516
}

tcw3/designer/tests_impl/lib.tcwdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import!("commit/remotetrigger.tcwdl");
22
import!("field/accessors.tcwdl");
3+
import!("field/bug_type_deduction.tcwdl");
34
import!("field/lifetime_elision.tcwdl");
45
import!("field/prop.tcwdl");
56
import!("func/inline.tcwdl");

0 commit comments

Comments
 (0)