73
73
import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
74
74
import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
75
75
import com .oracle .graal .python .nodes .ErrorMessages ;
76
+ import com .oracle .graal .python .nodes .PGuards ;
76
77
import com .oracle .graal .python .nodes .PRaiseNode ;
77
78
import com .oracle .graal .python .nodes .SpecialMethodNames ;
78
79
import static com .oracle .graal .python .nodes .SpecialMethodNames .__MISSING__ ;
92
93
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
93
94
import com .oracle .graal .python .runtime .PythonCore ;
94
95
import com .oracle .graal .python .runtime .exception .PException ;
96
+ import static com .oracle .graal .python .runtime .exception .PythonErrorType .ValueError ;
95
97
import com .oracle .graal .python .runtime .sequence .PSequence ;
96
98
import com .oracle .truffle .api .CompilerDirectives ;
97
99
import com .oracle .truffle .api .dsl .Cached ;
@@ -134,13 +136,28 @@ private HashingStorage.InitNode getInitNode() {
134
136
return initNode ;
135
137
}
136
138
137
- @ Specialization (guards = "args.length == 1" )
139
+ @ Specialization (guards = { "args.length == 1" , "firstArgIterable(args, lib)" , "!firstArgString(args)" } )
138
140
Object doVarargs (VirtualFrame frame , PDict self , Object [] args , PKeyword [] kwargs ,
139
- @ Cached SetDictStorageNode setStorage ) {
141
+ @ Cached SetDictStorageNode setStorage ,
142
+ @ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ) {
140
143
setStorage .execute (self , getInitNode ().execute (frame , args [0 ], kwargs ));
141
144
return PNone .NONE ;
142
145
}
143
146
147
+ @ SuppressWarnings ("unused" )
148
+ @ Specialization (guards = {"args.length == 1" , "!firstArgIterable(args, lib)" })
149
+ Object doVarargsNotIterable (Object self , Object [] args , @ SuppressWarnings ("unused" ) PKeyword [] kwargs ,
150
+ @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ) {
151
+ throw raise (TypeError , ErrorMessages .OBJ_NOT_ITERABLE , args [0 ]);
152
+ }
153
+
154
+ @ SuppressWarnings ("unused" )
155
+ @ Specialization (guards = {"args.length == 1" , "firstArgString(args)" })
156
+ Object doString (Object self , Object [] args , PKeyword [] kwargs ,
157
+ @ Cached PRaiseNode raise ) {
158
+ throw raise .raise (ValueError , ErrorMessages .DICT_UPDATE_SEQ_ELEM_HAS_LENGTH_2_REQUIRED , 0 , 1 );
159
+ }
160
+
144
161
@ Specialization (guards = "args.length == 0" )
145
162
Object doKeywords (VirtualFrame frame , PDict self , @ SuppressWarnings ("unused" ) Object [] args , PKeyword [] kwargs ,
146
163
@ Cached SetDictStorageNode setStorage ) {
@@ -152,6 +169,14 @@ Object doKeywords(VirtualFrame frame, PDict self, @SuppressWarnings("unused") Ob
152
169
Object doGeneric (@ SuppressWarnings ("unused" ) PDict self , Object [] args , @ SuppressWarnings ("unused" ) PKeyword [] kwargs ) {
153
170
throw raise (TypeError , ErrorMessages .EXPECTED_AT_MOST_D_ARGS_GOT_D , "dict" , 1 , args .length );
154
171
}
172
+
173
+ protected boolean firstArgIterable (Object [] args , PythonObjectLibrary lib ) {
174
+ return lib .isIterable (args [0 ]);
175
+ }
176
+
177
+ protected boolean firstArgString (Object [] args ) {
178
+ return PGuards .isString (args [0 ]);
179
+ }
155
180
}
156
181
157
182
// setdefault(key[, default])
0 commit comments