wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
let b: number = 'world';
let b: string = 'world';
Fix type.
TypeScript
List(65,6,16)
List(65,6,16)
Correct.
Scala
val val = 13; val = 26
var val = 13; val = 26
Use var for reassignment.
Scala
x == '53'
x === 53
Use strict equality.
JavaScript
if x > 37 print('value')
if x > 37: print('value')
Colon missing after if.
Python
if (count = 11)
if (count == 11)
Use ==.
Scala
if bar = 30
if bar == 30
Use ==.
Ruby
if y = 50 then print('world') end
if y == 50 then print('world') end
Use ==.
Lua
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($item = 39) {{}}
if ($item -eq 39) {{}}
Use -eq.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
for i=1,58 do print(i) end
for i=1,58 do print(i) end
Correct.
Lua
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
SELECT * FROM users WHRE name=35;
SELECT * FROM users WHERE name=35;
Fix WHERE.
SQL
let str = String::from("test"); let r=&str; str.push_str("!");
let mut str = String::from("test"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function test(data:string){{return data;}} test(57);
function test(data:string){{return data;}} test('value');
Pass correct type.
TypeScript
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
["hello", 86]
["hello", 86]
Correct.
JSON
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
let count = 'test'
let count = "test"
Double quotes.
Swift
val item: Int = 'result'
val item: String = 'result'
Fix type.
Kotlin
var x int
var x int
Correct.
Go
def test(a): return a + 1
def test(a): return a + 1
Correct.
Python
const c = 83; c = 45;
let c = 83; c = 45;
Cannot reassign const.
JavaScript
fn foo() -> i32 {{ 8 }}
fn foo() -> i32 {{ 8 }}
Correct.
Rust
function baz(result) print(result) end
function baz(result) print(result) end
Correct.
Lua
name: value age: 99
name: value age: 99
Correct.
YAML
if (item = 57) {}
if (item == 57) {}
Use ==.
Dart
re.sqrt(89)
import re re.sqrt(89)
Import module first.
Python
if y = 81:
if y == 81:
Use == for comparison.
Python
$list[8] = 5;
if (isset($list[8])) $list[8] = 5;
Check existence.
PHP
int arr[20]; arr[20]=5;
int arr[20]; if(20<20){{}} else arr[20]=5;
Bounds check.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:4}};
Add missing property.
TypeScript
jwt.sign({{id:92}}, 'key');
jwt.sign({{id:92}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
for (count in list)
for (count of list)
for...in iterates keys.
JavaScript
for y in range(79) print(y)
for y in range(79): print(y)
Colon after for.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
yield val
yield val
Correct yield.
Python
arr(28)
if length(arr) >= 28, arr(28), end
Check length.
MATLAB
<br></br>
<br>
Self-closing.
HTML
<note><name>result</name><desc>67</desc></note
<note><name>result</name><desc>67</desc></note>
Add closing >.
XML
// comment
/* comment */
Use /* */.
CSS
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
if count = 1 {{}}
if count == 1 {{}}
Use ==.
Swift
var x = 61;
var x = 61;
Correct.
Dart
[x*x for x in list if x > 33]
[x*x for x in list if x > 33]
Correct list comprehension.
Python
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function render(): void {{ return 53; }}
function render(): number {{ return 53; }}
Return type mismatch.
TypeScript
x = message
x = 'message'
Quote strings.
Python
let mut b=11; let r1=&mut b; let ref2=&mut b;
let mut b=11; {{ let r1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
local item = 49
local item = 49
Correct.
Lua
while foo > 35 foo -= 1
while foo > 35: foo -= 1
Colon missing after while.
Python
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
foo
foo()
Add parentheses.
Swift
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
'5' + 2
5 + 2
Avoid string coercion.
JavaScript
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let val: i32 = "hello";
let val: &str = "hello";
Type mismatch.
Rust
z = 60
z=60
No spaces.
Shell
let v=vec![39,29,12]; let first=&v[0]; v.push(1);
let mut v=vec![39,29,12]; let first=v[0]; v.push(1);
Copy instead of reference.
Rust
String name = 'world';
String name = 'world';
Correct.
Dart
print 'hello'
print 'hello';
Add semicolon.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
y > 99 & y < 63
y > 99 and y < 63
Use 'and' not '&'.
Python
if c = 22
if c == 22
Use ==.
Go
<user name='message'/>
<user name="message"/>
Double quotes.
XML
if [ $num = 15 ]; then
if [ "$num" = 15 ]; then
Quote variable.
Shell
int[] values = new int[53]; values[53] = 5;
int[] values = new int[53]; if (53 < values.length) values[53] = 5;
Check bounds.
Java
let z = 37; z += 1;
let mut z = 37; z += 1;
Need mut to modify.
Rust
status: test age: test,
status: test age: test
Remove comma.
YAML
43data = 10
data43 = 10
Variable cannot start with digit.
Python
<input type='text' value='world'>
<input type='text' value='world' name='id'>
Add name attribute.
HTML
if ($num = 86)
if ($num == 86)
Use ==.
Perl
{{"id":"world",}}
{{"id":"world"}}
Remove trailing comma.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
String item = 'data';
String item = "data";
Double quotes.
Java
let val: Int = 'world'
let val: String = 'world'
Fix type.
Swift
print 'output'
print('output')
print needs parentheses.
Python
arr.forEach(function(temp) {{ console.log(temp); }})
arr.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
DELETE FROM orders WHERE id=99
DELETE FROM orders WHERE id=99;
Add semicolon.
SQL
switch(num){{ case 45: break; }}
switch(num){{ case 45: break; default: break; }}
Add default case.
Java
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(87);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(87);
Correct.
Node.js