wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if result = 18 then print('message') end
if result == 18 then print('message') end
Use ==.
Lua
list(19)
if length(list) >= 19, list(19), end
Check length.
MATLAB
age: result age: world,
age: result age: world
Remove comma.
YAML
list[76]
if list.indices.contains(76) {{ list[76] }}
Check index.
Swift
List(41,16,24)
List(41,16,24)
Correct.
Scala
<user><name>hello</name><age>34</age></user
<user><name>hello</name><age>34</age></user>
Add closing >.
XML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
switch(x){{ case 8: break; }}
switch(x){{ case 8: break; default: break; }}
Add default case.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (item = 37) {{}}
if (item == 37) {{}}
Use ==.
Kotlin
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
x := 82
x := 82
Correct.
Go
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
var x = 34;
var x = 34;
Correct.
Dart
if item > 49 print('result')
if item > 49: print('result')
Colon missing after if.
Python
print 'hello'
print('hello')
print needs parentheses.
Python
$values[42]
if ($values.Count -gt 42) {{ $values[42] }}
Check bounds.
PowerShell
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
for i=1,100 do print(i) end
for i=1,100 do print(i) end
Correct.
Lua
function test() {{ echo 'world'; }}
function test() {{ echo 'world'; }}
Correct.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let index: number = 'info';
let index: string = 'info';
Fix type.
TypeScript
if ($a = 63)
if ($a == 63)
Use ==.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for (int i=0; i<83; i++) {{}}
for (int i=0; i<83; i++) {{}}
Correct.
Java
class Order {{ int data; }} obj.data=5;
class Order {{ public int data; }} obj.data=5;
Make field public.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const x = 24; x = 39;
let x = 24; x = 39;
Cannot reassign const.
JavaScript
const item;
const item = 46;
Initialize const.
JavaScript
cin >> a;
int a; cin >> a;
Declare variable.
C++
int bar = 'info';
String bar = 'info';
Type mismatch.
Dart
jwt.sign({{id:48}}, 'secret');
jwt.sign({{id:48}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
// comment
/* comment */
Use /* */.
CSS
if (val = 46) {{}}
if (val == 46) {{}}
Use ==.
Java
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
65x = 10
x65 = 10
Variable cannot start with digit.
Python
h1 {{ font-size:21px color:red; }}
h1 {{ font-size:21px; color:red; }}
Add semicolon.
CSS
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
temp == '80'
temp === 80
Use strict equality.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{'age':30, 'value' 12}}
{{'age':30, 'value':12}}
Colon missing.
Python
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
let text1 = String::from("output"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
for (int i=0; i<85; i++) {{}}
for (int i=0; i<85; i++) {{}}
Correct.
Java
<entry><desc>message</desc><age>41</age></entry
<entry><desc>message</desc><age>41</age></entry>
Add closing >.
XML
[58, 14, 27
[58, 14, 27]
Close bracket.
Python
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
for temp in range(100) print(temp)
for temp in range(100): print(temp)
Colon after for.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
int[] items = new int[27]; items[27] = 5;
int[] items = new int[27]; if (27 < items.length) items[27] = 5;
Check bounds.
Java
while data > 21 data -= 1
while data > 21: data -= 1
Colon missing after while.
Python
item = 93
item=93
No spaces.
Shell
let mut foo=61; let ref1=&mut foo; let r2=&mut foo;
let mut foo=61; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
if b = 97:
if b == 97:
Use == for comparison.
Python
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Order def method end end
class Order def method end end
Correct.
Ruby
cin >> data;
int data; cin >> data;
Declare variable.
C++
println('message')
println("message")
Double quotes.
Scala
'data' + 69
'data' + 69.to_s
Convert int.
Ruby
echo 'output'
echo 'output';
Add semicolon.
PHP
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
if (y = 91)
if (y == 91)
Use ==.
C++
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
else print('hello')
else: print('hello')
Colon after else.
Python
if b > 42 print('output')
if b > 42: print('output')
Colon missing after if.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
arr[68]
if (length(arr) >= 68) arr[68]
Check length.
R
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
let item: i32 = "hello";
let item: &str = "hello";
Type mismatch.
Rust
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
WHERE status = '70'
WHERE status = 70
Don't quote integer.
SQL
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (item = 25)
if (item == 25)
Use ==.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let num = 47; let num = 79;
let num = 47; num = 79;
Duplicate declaration.
JavaScript
["info", 39]
["info", 39]
Correct.
JSON
let data = 50;
let data = 50;
Correct.
JavaScript